Skip to content

Commit 66125a4

Browse files
committed
josedev_1.0_20230223_1128
1 parent 48132b9 commit 66125a4

6 files changed

Lines changed: 464 additions & 3 deletions

test/test_export_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from toolkit.machine_learning import export_model
2+
3+
from sklearn.neighbors import KNeighborsClassifier
4+
import os
5+
6+
import pytest
7+
8+
def test_export_model():
9+
model = KNeighborsClassifier()
10+
dir_model = os.path.join(os.getcwd(), 'model')
11+
# dir_model = os.getcwd() + '\\model'
12+
# # Guardamos en una variable el directorio del script
13+
# dir_script = os.path.dirname(os.path.abspath(__file__))
14+
# # Guardamos la ubicacion del modelo
15+
# dir_model = os.path.join(dir_script, 'model')
16+
17+
assert export_model(model, dir_model=dir_model, name_model='model_the_best') == None

test/test_import_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from toolkit.machine_learning import import_model
2+
3+
from sklearn.neighbors import KNeighborsClassifier
4+
import os
5+
6+
import pytest
7+
8+
def test_import_model():
9+
model_import = KNeighborsClassifier()
10+
dir_model = os.path.join(os.getcwd(), 'model_KNN')
11+
# dir_model = os.getcwd() + '\\model_KNN'
12+
# # Guardamos en una variable el directorio del script
13+
# dir_script = os.path.dirname(os.path.abspath(__file__))
14+
# # Guardamos la ubicacion del modelo
15+
# dir_model = os.path.join(dir_script, 'model_KNN')
16+
17+
assert import_model(dir_model=dir_model, name_model='model_KNN') == model_import
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from toolkit.machine_learning import predict_model_classification
2+
3+
from sklearn.neighbors import KNeighborsClassifier
4+
import pandas as pd
5+
6+
import pytest
7+
8+
def test_predict_model_classification():
9+
model_import = KNeighborsClassifier()
10+
X_test = pd.DataFrame({'sex':[0, 1],
11+
'hypertension': [1, 0],
12+
'heart_disease':[1, 0],
13+
'Residence_type':[0, 1]}
14+
)
15+
y_test = pd.DataFrame({'':[1, 1]})
16+
y_pred_test = [0, 0] # [0 0]
17+
18+
assert predict_model_classification(model_import, X_test, y_test, test_score=False) == X_test, y_pred_test
19+
20+
# X_test_r, y_pred_test_r = predict_model_classification(model_import, X_test, y_test, test_score=False)
21+
# assert X_test_r == X_test
22+
# assert y_pred_test_r.tolist() == y_pred_test
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

test/test_show_scoring.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from toolkit.machine_learning import show_scoring
2+
import pandas as pd
3+
4+
import pytest
5+
6+
def test_show_scoring():
7+
y_test = pd.DataFrame({'':[1, 1]})
8+
y_pred_test = [0, 0] # [0 0]
9+
10+
dict_scoring = show_scoring(y_test, y_pred_test, label='TEST', round=1, auc_sc=False, roc_auc_sc=False, confusion_matrix_sc=False)
11+
12+
assert dict_scoring['accu_r'] == 0.0
13+
assert dict_scoring['auc_r'] == None
14+
assert dict_scoring['roc_auc_r'] == None
15+
assert dict_scoring['conf_mat_r'] == None

0 commit comments

Comments
 (0)