|
| 1 | +from toolkit.machine_learning import processing_model_classification |
| 2 | + |
| 3 | +from sklearn.neighbors import KNeighborsClassifier |
| 4 | +import pandas as pd |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +def test_processing_model_classification(): |
| 9 | + model = KNeighborsClassifier() |
| 10 | + df = pd.DataFrame({'sex': [0, 1, 1, 0, 1, 1, 0], 'hypertension': [0, 0, 1, 1, 0, 0, 1], 'heart_disease': [0, 0, 1, 1, 0, 1, 1], 'Residence_type': [1, 1, 0, 1, 0, 1, 0], 'stroke': [0, 1, 1, 0, 1, 0, 1]}) |
| 11 | + X = df.drop(columns=['stroke']) |
| 12 | + y = df['stroke'] |
| 13 | + |
| 14 | + X_train = pd.DataFrame({'sex':[0, 1, 1, 1, 0], |
| 15 | + 'hypertension': [0, 1, 0, 0, 1], |
| 16 | + 'heart_disease':[0, 1, 0, 1, 1], |
| 17 | + 'Residence_type':[1, 0, 0, 1, 1]} |
| 18 | + ) |
| 19 | + X_test = pd.DataFrame({'sex':[0, 1], |
| 20 | + 'hypertension': [1, 0], |
| 21 | + 'heart_disease':[1, 0], |
| 22 | + 'Residence_type':[0, 1]} |
| 23 | + ) |
| 24 | + y_train = pd.DataFrame({'':[0, 1, 1, 0, 0]}) |
| 25 | + y_test = pd.DataFrame({'':[1, 1]}) |
| 26 | + y_pred_train = [0, 0, 0, 0, 0] # [0 0 0 0 0] |
| 27 | + y_pred_test = [0, 0] # [0 0] |
| 28 | + |
| 29 | + model_r, X_train_r, X_test_r, y_train_r, y_test_r, y_pred_train_r, y_pred_test_r = processing_model_classification(model, X, y, test_size_split=0.20, shuffle_split=True, |
| 30 | + random_state_split=32, standardScaler=False, train_score=True, test_score=False) |
| 31 | + |
| 32 | + assert model_r == model |
| 33 | + assert X_train_r == X_train |
| 34 | + assert X_test_r == X_test |
| 35 | + assert y_train_r == y_train |
| 36 | + assert y_test_r == y_test |
| 37 | + assert y_pred_train_r == y_pred_train |
| 38 | + assert y_pred_test_r == y_pred_test |
| 39 | + |
| 40 | + # assert isinstance(model_r, model) |
| 41 | + # assert isinstance(X_train_r, X_train) |
| 42 | + # assert isinstance(X_test_r, X_test) |
| 43 | + # assert isinstance(y_train_r, y_train) |
| 44 | + # assert isinstance(y_test_r, y_test) |
| 45 | + # assert isinstance(y_pred_train_r, y_pred_train) |
| 46 | + # assert isinstance(y_pred_test_r, y_pred_test) |
| 47 | + |
| 48 | + # assert processing_model_classification(model, X, y, test_size_split=0.20, shuffle_split=True, standardScaler=False, |
| 49 | + # train_score=True, test_score=False) == model, X_train, X_test, y_train, y_test, y_pred_train, y_pred_test |
0 commit comments