mertkarabacak commited on
Commit
903e362
1 Parent(s): 147cb13

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
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 xgboost import XGBClassifier
179
- y1_xgb = XGBClassifier(**y1_params)
180
- y1_model_xgb = y1_xgb.fit(x1, y1)
181
- y1_explainer_xgb = shap.TreeExplainer(y1_model_xgb)
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 y4_predict_xgb(*args):
329
- df4 = pd.DataFrame([args], columns=x4.columns)
330
- df4 = df4.astype({col: "category" for col in categorical_columns4})
331
- d4 = dict.fromkeys(df4.select_dtypes(np.int64).columns, np.int34)
332
- df4 = df4.astype(d4)
333
- pos_pred = y4_model_xgb.predict_proba(df4)
334
  return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
335
 
336
- def y4_predict_lgb(*args):
337
- df4 = pd.DataFrame([args], columns=x4.columns)
338
- df4 = df4.astype({col: "category" for col in categorical_columns4})
339
- d4 = dict.fromkeys(df4.select_dtypes(np.int64).columns, np.int34)
340
- df4 = df4.astype(d4)
341
- pos_pred = y4_model_lgb.predict_proba(df4)
342
  return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
343
 
344
- def y4_predict_cb(*args):
345
- df4 = pd.DataFrame([args], columns=x4.columns)
346
- df4 = df4.astype({col: "category" for col in categorical_columns4})
347
- pos_pred = y4_model_cb.predict(Pool(df4, cat_features = categorical_columns4), prediction_type='Probability')
348
  return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
349
 
350
- def y4_predict_rf(*args):
351
- df4 = pd.DataFrame([args], columns=x4_rf.columns)
352
- df4 = df4.astype({col: "category" for col in categorical_columns4})
353
- d4 = dict.fromkeys(df4.select_dtypes(np.int64).columns, np.int34)
354
- df4 = df4.astype(d4)
355
- pos_pred = y4_model_rf.predict_proba(df4)
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.