-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathml_model_pipeline.py
64 lines (44 loc) · 1.77 KB
/
ml_model_pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import joblib
# load trained model
def load_ml_model():
lgr = joblib.load('model_updates/lgr_mm.sav')
# knn = joblib.load('model_updates/knn_sd.sav')
svc = joblib.load('model_updates/svc_sd.sav')
dt = joblib.load('model_updates/dt.sav')
rdf = joblib.load('model_updates/rdf.sav')
ada = joblib.load('model_updates/ada.sav')
lgbm = joblib.load('model_updates/lgbm.sav')
return lgr, svc, dt, rdf, ada, lgbm
# feature engineering process 1
def set_bmi(row):
row.loc[:, 'BM_DESC_Healthy'] = 0
row.loc[:, 'BM_DESC_Obese'] = 0
row.loc[:, 'BM_DESC_Over'] = 0
row.loc[:, 'BM_DESC_Under'] = 0
if row['BMI'].values < 18.5:
row.loc[row['BMI'] < 18.5, 'BM_DESC_Under'] = 1
elif (row["BMI"].values >= 18.5) and (row["BMI"].values <= 24.9):
row.loc[(row["BMI"] >= 18.5) & (
row["BMI"] <= 24.9), 'BM_DESC_Healthy'] = 1
elif (row["BMI"] >= 25).values and (row["BMI"].values <= 29.9):
row.loc[(row["BMI"] >= 25) & (row["BMI"] <= 29.9), 'BM_DESC_Over'] = 1
elif row["BMI"].values >= 30:
row.loc[row["BMI"] >= 30, 'BM_DESC_Obese'] = 1
return row
# feature engineering process 2
def set_insulin(row):
row.loc[:, 'INSULIN_DESC_Abnormal'] = 0
row.loc[:, 'INSULIN_DESC_Normal'] = 0
if (row["Insulin"].values >= 16) and (row["Insulin"].values <= 166):
row.loc[(row["Insulin"] >= 16) & (
row["Insulin"] <= 166), 'INSULIN_DESC_Normal'] = 1
else:
row.loc[:, 'INSULIN_DESC_Abnormal'] = 1
return row
# load scaler for machine learning model
def load_scaler_ml():
min_max_scaler = joblib.load(
'model_updates/MinMaxScaler().pkl')
standard_scaler = joblib.load(
'model_updates/StandardScaler().pkl')
return min_max_scaler, standard_scaler