mertkarabacak
commited on
Commit
•
903e362
1
Parent(s):
147cb13
Upload app.py
Browse files
app.py
CHANGED
@@ -175,10 +175,10 @@ y4_params = {'objective': 'binary', 'booster': 'gbtree', 'lambda': 9.0811397283
|
|
175 |
y5_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.0016190622681086678, 'lambda_l2': 0.00041749233000407354, 'num_leaves': 2, 'feature_fraction': 0.5730231365909909, 'bagging_fraction': 0.6964002116636187, 'bagging_freq': 6, 'min_child_samples': 44, 'metric': 'binary_logloss', 'verbosity': -1, 'random_state': 31}
|
176 |
|
177 |
#Training models.
|
178 |
-
from
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
|
183 |
from sklearn.ensemble import RandomForestClassifier as rf
|
184 |
y2_rf = rf(**y2_params)
|
@@ -325,34 +325,34 @@ def y4_predict_rf(*args):
|
|
325 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
326 |
|
327 |
#Define predict for y5 (complications).
|
328 |
-
def
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
pos_pred =
|
334 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
335 |
|
336 |
-
def
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
pos_pred =
|
342 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
343 |
|
344 |
-
def
|
345 |
-
|
346 |
-
|
347 |
-
pos_pred =
|
348 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
349 |
|
350 |
-
def
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
pos_pred =
|
356 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
357 |
|
358 |
#Define function for wrapping feature labels.
|
|
|
175 |
y5_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.0016190622681086678, 'lambda_l2': 0.00041749233000407354, 'num_leaves': 2, 'feature_fraction': 0.5730231365909909, 'bagging_fraction': 0.6964002116636187, 'bagging_freq': 6, 'min_child_samples': 44, 'metric': 'binary_logloss', 'verbosity': -1, 'random_state': 31}
|
176 |
|
177 |
#Training models.
|
178 |
+
from lightgbm import LGBMClassifier
|
179 |
+
lgb = LGBMClassifier(**y4_params)
|
180 |
+
y4_model_lgb = lgb.fit(x4, y4)
|
181 |
+
y4_explainer_lgb = shap.TreeExplainer(y4_model_lgb)
|
182 |
|
183 |
from sklearn.ensemble import RandomForestClassifier as rf
|
184 |
y2_rf = rf(**y2_params)
|
|
|
325 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
326 |
|
327 |
#Define predict for y5 (complications).
|
328 |
+
def y5_predict_xgb(*args):
|
329 |
+
df5 = pd.DataFrame([args], columns=x5.columns)
|
330 |
+
df5 = df5.astype({col: "category" for col in categorical_columns5})
|
331 |
+
d5 = dict.fromkeys(df5.select_dtypes(np.int64).columns, np.int35)
|
332 |
+
df5 = df5.astype(d5)
|
333 |
+
pos_pred = y5_model_xgb.predict_proba(df5)
|
334 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
335 |
|
336 |
+
def y5_predict_lgb(*args):
|
337 |
+
df5 = pd.DataFrame([args], columns=x5.columns)
|
338 |
+
df5 = df5.astype({col: "category" for col in categorical_columns5})
|
339 |
+
d5 = dict.fromkeys(df5.select_dtypes(np.int64).columns, np.int35)
|
340 |
+
df5 = df5.astype(d5)
|
341 |
+
pos_pred = y5_model_lgb.predict_proba(df5)
|
342 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
343 |
|
344 |
+
def y5_predict_cb(*args):
|
345 |
+
df5 = pd.DataFrame([args], columns=x5.columns)
|
346 |
+
df5 = df5.astype({col: "category" for col in categorical_columns5})
|
347 |
+
pos_pred = y5_model_cb.predict(Pool(df5, cat_features = categorical_columns5), prediction_type='Probability')
|
348 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
349 |
|
350 |
+
def y5_predict_rf(*args):
|
351 |
+
df5 = pd.DataFrame([args], columns=x5_rf.columns)
|
352 |
+
df5 = df5.astype({col: "category" for col in categorical_columns5})
|
353 |
+
d5 = dict.fromkeys(df5.select_dtypes(np.int64).columns, np.int35)
|
354 |
+
df5 = df5.astype(d5)
|
355 |
+
pos_pred = y5_model_rf.predict_proba(df5)
|
356 |
return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
|
357 |
|
358 |
#Define function for wrapping feature labels.
|