mertkarabacak commited on
Commit
9aba401
1 Parent(s): 03b6f31

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +512 -0
app.py ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ HF_TOKEN = os.getenv("HF_TOKEN")
3
+
4
+ import numpy as np
5
+ import pandas as pd
6
+
7
+ import sklearn
8
+ import sklearn.metrics
9
+ from sklearn.metrics import roc_auc_score, roc_curve, precision_recall_curve, auc, precision_score, recall_score, f1_score, classification_report, accuracy_score, confusion_matrix, ConfusionMatrixDisplay, matthews_corrcoef
10
+ from sklearn.model_selection import train_test_split
11
+ from sklearn.calibration import calibration_curve
12
+
13
+ from scipy import stats as st
14
+ from random import randrange
15
+ from matplotlib import pyplot as plt
16
+ from scipy.special import softmax
17
+
18
+ import xgboost as xgb
19
+ import lightgbm as lgb
20
+ import catboost as cb
21
+ from catboost import Pool
22
+ from sklearn.ensemble import RandomForestClassifier
23
+
24
+
25
+ import optuna
26
+
27
+ import shap
28
+
29
+ import gradio as gr
30
+
31
+ import random
32
+
33
+ #Read and redefine data.
34
+
35
+ from datasets import load_dataset
36
+ data = load_dataset("mertkarabacak/NSQIP-CDA", data_files="cda_imputed.csv", use_auth_token = HF_TOKEN)
37
+
38
+ data = pd.DataFrame(data['train'])
39
+ variables = ['SEX', 'TRANST', 'AGE', 'SURGSPEC', 'HEIGHT', 'WEIGHT', 'DIABETES', 'SMOKE', 'DYSPNEA', 'FNSTATUS2', 'VENTILAT', 'HXCOPD', 'ASCITES', 'HXCHF', 'HYPERMED', 'RENAFAIL', 'DIALYSIS', 'DISCANCR', 'WNDINF', 'STEROID', 'WTLOSS', 'BLEEDDIS', 'TRANSFUS', 'PRSODM', 'PRBUN', 'PRCREAT', 'PRWBC', 'PRHCT', 'PRPLATE', 'ASACLAS', 'READMISSION1', 'BMI', 'RACE', 'LEVELS', 'ADVERSE_OUTCOME']
40
+ data = data[variables]
41
+
42
+ data['SEX'] = data['SEX'].replace(['male'], 'Male')
43
+ data['SEX'] = data['SEX'].replace(['female'], 'Female')
44
+
45
+ print(data.columns)
46
+
47
+ #Define outcomes.
48
+
49
+ x = data
50
+ y1 = data.pop('ADVERSE_OUTCOME')
51
+ y1 = (y1 == "Yes").astype(int)
52
+
53
+ categorical_columns = list(x.select_dtypes('object').columns)
54
+
55
+ x = x.astype({col: "category" for col in categorical_columns})
56
+
57
+ #Prepare data for AE (y1).
58
+
59
+ y1_data_xgb = xgb.DMatrix(x, label=y1, enable_categorical=True)
60
+ y1_data_lgb = lgb.Dataset(x, label=y1)
61
+ y1_data_cb = Pool(data=x, label=y1, cat_features=categorical_columns)
62
+
63
+ #Prepare data for Random Forest models.
64
+
65
+ x_rf = x
66
+ categorical_columns = list(x_rf.select_dtypes('category').columns)
67
+ x_rf = x_rf.astype({col: "category" for col in categorical_columns})
68
+ le = sklearn.preprocessing.LabelEncoder()
69
+ for col in categorical_columns:
70
+ x_rf[col] = le.fit_transform(x_rf[col].astype(str))
71
+ d1 = dict.fromkeys(x_rf.select_dtypes(np.int64).columns, str)
72
+ x_rf = x_rf.astype(d1)
73
+
74
+ #Assign unique values as answer options.
75
+
76
+ unique_sex = ['Male', 'Female']
77
+ unique_race = ['White', 'Black or African American', 'Hispanic', 'Asian', 'Other', 'Unknown']
78
+ unique_transt = ['Not transferred', 'Transferred', 'Unknown']
79
+ unique_diabetes = ['No', 'Yes']
80
+ unique_smoke = ['No', 'Yes']
81
+ unique_dyspnea = ['No', 'Yes']
82
+ unique_ventilat = ['No', 'Yes']
83
+ unique_hxcopd = ['No', 'Yes']
84
+ unique_ascites = ['No', 'Yes']
85
+ unique_hxchf = ['No', 'Yes']
86
+ unique_hypermed = ['No', 'Yes']
87
+ unique_renafail = ['No', 'Yes']
88
+ unique_dialysis = ['No', 'Yes']
89
+ unique_discancr = ['No', 'Yes']
90
+ unique_steroid = ['No', 'Yes']
91
+ unique_wtloss = ['No', 'Yes']
92
+ unique_bleeddis = ['No', 'Yes']
93
+ unique_transfus = ['No', 'Yes']
94
+ unique_wndinf = ['No', 'Yes']
95
+ unique_asaclas = ['1-No Disturb', '2-Mild Disturb','3-Severe Disturb']
96
+ unique_fnstatus2 = ['Independent', 'Partially Dependent', 'Totally Dependent', 'Unknown']
97
+ unique_surgspec = ['Neurosurgery', 'Orthopedics']
98
+ unique_levels = ['Single', 'Multiple']
99
+
100
+ #Assign hyperparameters.
101
+
102
+ y1_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 0.3506223423303318, 'alpha': 0.010119011691233883, 'max_depth': 9, 'eta': 0.965102554386191, 'gamma': 1.119572508228617e-08, 'grow_policy': 'depthwise'}
103
+
104
+ y1_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 8.520929262020913e-05, 'lambda_l2': 1.6655311531708117, 'num_leaves': 136, 'feature_fraction': 0.7509810402777333, 'bagging_fraction': 0.9102746088494693, 'bagging_freq': 1, 'min_child_samples': 55}
105
+
106
+ y1_cb_params = {'objective': 'Logloss', 'colsample_bylevel': 0.062057010685389026, 'depth': 3, 'boosting_type': 'Plain', 'bootstrap_type': 'MVS'}
107
+
108
+ y1_rf_params = {'criterion': 'gini', 'bootstrap': 'auto', 'max_features': 'auto', 'max_depth': 95, 'n_estimators': 10, 'min_samples_leaf': 1, 'min_samples_split': 2}
109
+
110
+
111
+ #Modeling for y1/AE.
112
+
113
+ y1_model_xgb = xgb.train(params=y1_xgb_params, dtrain=y1_data_xgb)
114
+ y1_explainer_xgb = shap.TreeExplainer(y1_model_xgb)
115
+
116
+ y1_model_lgb = lgb.train(params=y1_lgb_params, train_set=y1_data_lgb)
117
+ y1_explainer_lgb = shap.TreeExplainer(y1_model_lgb)
118
+
119
+ y1_model_cb = cb.train(pool=y1_data_cb, params=y1_cb_params)
120
+ y1_explainer_cb = shap.TreeExplainer(y1_model_cb)
121
+
122
+ from sklearn.ensemble import RandomForestClassifier as rf
123
+ y1_rf = rf(**y1_rf_params)
124
+ y1_model_rf = y1_rf.fit(x_rf, y1)
125
+ y1_explainer_rf = shap.TreeExplainer(y1_model_rf)
126
+
127
+
128
+ #Define predict for y1/AE.
129
+
130
+ def y1_predict_xgb(*args):
131
+ df_xgb = pd.DataFrame([args], columns=x.columns)
132
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns})
133
+ pos_pred = y1_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
134
+ return {"Prolonged LOS": float(pos_pred[0]), "Not Prolonged LOS": 1 - float(pos_pred[0])}
135
+
136
+ def y1_predict_lgb(*args):
137
+ df = pd.DataFrame([args], columns=data.columns)
138
+ df = df.astype({col: "category" for col in categorical_columns})
139
+ pos_pred = y1_model_lgb.predict(df)
140
+ return {"Prolonged LOS": float(pos_pred[0]), "Not Prolonged LOS": 1 - float(pos_pred[0])}
141
+
142
+ def y1_predict_cb(*args):
143
+ df_cb = pd.DataFrame([args], columns=x.columns)
144
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns})
145
+ pos_pred = y1_model_cb.predict(Pool(df_cb, cat_features = categorical_columns), prediction_type='Probability')
146
+ return {"Prolonged LOS": float(pos_pred[0][1]), "Not Prolonged LOS": float(pos_pred[0][0])}
147
+
148
+ def y1_predict_rf(*args):
149
+ df = pd.DataFrame([args], columns=x_rf.columns)
150
+ df = df.astype({col: "category" for col in categorical_columns})
151
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
152
+ df = df.astype(d)
153
+ pos_pred = y1_model_rf.predict_proba(df)
154
+ return {"Prolonged LOS": float(pos_pred[0][1]), "Not Prolonged LOS": float(pos_pred[0][0])}
155
+
156
+
157
+ #Define interpret for y1/AE.
158
+
159
+ def y1_interpret_xgb(*args):
160
+ df = pd.DataFrame([args], columns=x.columns)
161
+ df = df.astype({col: "category" for col in categorical_columns})
162
+ shap_values = y1_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
163
+ scores_desc = list(zip(shap_values[0], x.columns))
164
+ scores_desc = sorted(scores_desc)
165
+ fig_m = plt.figure(facecolor='white')
166
+ fig_m.set_size_inches(14, 10)
167
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
168
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
169
+ plt.yticks(fontsize=12)
170
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
171
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
172
+ return fig_m
173
+
174
+ def y1_interpret_lgb(*args):
175
+ df = pd.DataFrame([args], columns=x.columns)
176
+ df = df.astype({col: "category" for col in categorical_columns})
177
+ shap_values = y1_explainer_lgb.shap_values(df)
178
+ scores_desc = list(zip(shap_values[0][0], x.columns))
179
+ scores_desc = sorted(scores_desc)
180
+ fig_m = plt.figure(facecolor='white')
181
+ fig_m.set_size_inches(14, 10)
182
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
183
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
184
+ plt.yticks(fontsize=12)
185
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
186
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
187
+ return fig_m
188
+
189
+ def y1_interpret_cb(*args):
190
+ df = pd.DataFrame([args], columns=x.columns)
191
+ df = df.astype({col: "category" for col in categorical_columns})
192
+ shap_values = y1_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns))
193
+ scores_desc = list(zip(shap_values[0], x.columns))
194
+ scores_desc = sorted(scores_desc)
195
+ fig_m = plt.figure(facecolor='white')
196
+ fig_m.set_size_inches(14, 10)
197
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
198
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
199
+ plt.yticks(fontsize=12)
200
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
201
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
202
+ return fig_m
203
+
204
+ def y1_interpret_rf(*args):
205
+ df = pd.DataFrame([args], columns=x_rf.columns)
206
+ df = df.astype({col: "category" for col in categorical_columns})
207
+ shap_values = y1_explainer_rf.shap_values(df)
208
+ scores_desc = list(zip(shap_values[0][0], x_rf.columns))
209
+ scores_desc = sorted(scores_desc)
210
+ fig_m = plt.figure(facecolor='white')
211
+ fig_m.set_size_inches(14, 10)
212
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
213
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
214
+ plt.yticks(fontsize=12)
215
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
216
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
217
+ return fig_m
218
+
219
+
220
+ with gr.Blocks(title = "NSQIP-CDA") as demo:
221
+
222
+ gr.Markdown(
223
+ """
224
+ """
225
+ )
226
+
227
+ gr.Markdown(
228
+ """
229
+ # Prediction Tool
230
+
231
+ ## Adverse Short-Term Postoperative Outcomes Following Cervical Disc Arthroplasty
232
+
233
+ **The publication describing the details of this predictive tool will be posted here upon the acceptance of publication.**
234
+
235
+ ### Disclaimer
236
+
237
+ The American College of Surgeons National Surgical Quality Improvement Program and the hospitals participating in the ACS NSQIP are the source of the data used herein; they have not been verified and are not responsible for the statistical validity of the data analysis or the conclusions derived by the authors.
238
+
239
+ The predictive tool located on this web page is for general health information only. This prediction tool should not be used in place of professional medical service for any disease or concern. Users of the prediction tool shouldn't base their decisions about their own health issues on the information presented here. You should ask any questions to your own doctor or another healthcare professional.
240
+
241
+ The authors of the study mentioned above make no guarantees or representations, either express or implied, as to the completeness, timeliness, comparative or contentious nature, or utility of any information contained in or referred to in this prediction tool. The risk associated with using this prediction tool or the information in this predictive tool is not at all assumed by the authors. The information contained in the prediction tools may be outdated, not complete, or incorrect because health-related information is subject to frequent change and multiple confounders.
242
+
243
+ No express or implied doctor-patient relationship is established by using the prediction tool. The prediction tools on this website are not validated by the authors. Users of the tool are not contacted by the authors, who also do not record any specific information about them.
244
+
245
+ You are hereby advised to seek the advice of a doctor or other qualified healthcare provider before making any decisions, acting, or refraining from acting in response to any healthcare problem or issue you may be experiencing at any time, now or in the future. By using the prediction tool, you acknowledge and agree that neither the authors nor any other party are or will be liable or otherwise responsible for any decisions you make, actions you take, or actions you choose not to take as a result of using any information presented here.
246
+
247
+ By using this tool, you accept all of the above terms.
248
+
249
+ """
250
+ )
251
+
252
+ gr.Markdown(
253
+ """
254
+
255
+ ### Prolonged Length of Stay Prediction Model for PCF Surgery
256
+
257
+ """
258
+ )
259
+
260
+
261
+ with gr.Row():
262
+
263
+ with gr.Column():
264
+
265
+ AGE = gr.Slider(label="Age", minimum=17, maximum=99, step=1, randomize=True)
266
+
267
+ SEX = gr.Radio(
268
+ label="Sex",
269
+ choices=unique_sex,
270
+ type='index',
271
+ value=lambda: random.choice(unique_sex),
272
+ )
273
+
274
+ RACE = gr.Radio(
275
+ label="Race",
276
+ choices=unique_race,
277
+ type='index',
278
+ value=lambda: random.choice(unique_race),
279
+ )
280
+
281
+ HEIGHT = gr.Slider(label="Height (in meters)", minimum=1.0, maximum=2.25, step=0.01, randomize=True)
282
+
283
+ WEIGHT = gr.Slider(label="Weight (in kilograms)", minimum=20, maximum=200, step=1, randomize=True)
284
+
285
+ BMI = gr.Slider(label="BMI", minimum=10, maximum=70, step=1, randomize=True)
286
+
287
+ TRANST = gr.Radio(
288
+ label="Transfer Status",
289
+ choices=unique_transt,
290
+ type='index',
291
+ value=lambda: random.choice(unique_transt),
292
+ )
293
+
294
+ SURGSPEC = gr.Radio(
295
+ label="Surgical Specialty",
296
+ choices=unique_surgspec,
297
+ type='index',
298
+ value=lambda: random.choice(unique_surgspec),
299
+ )
300
+
301
+ SMOKE = gr.Radio(
302
+ label="Smoking Status",
303
+ choices=unique_smoke,
304
+ type='index',
305
+ value=lambda: random.choice(unique_smoke),
306
+ )
307
+
308
+ DIABETES = gr.Radio(
309
+ label="Diabetes",
310
+ choices=unique_diabetes,
311
+ type='index',
312
+ value=lambda: random.choice(unique_diabetes),
313
+ )
314
+
315
+ DYSPNEA = gr.Radio(
316
+ label="Dyspnea",
317
+ choices=unique_dyspnea,
318
+ type='index',
319
+ value=lambda: random.choice(unique_dyspnea),
320
+ )
321
+
322
+ VENTILAT = gr.Radio(
323
+ label="Ventilator Dependency",
324
+ choices=unique_ventilat,
325
+ type='index',
326
+ value=lambda: random.choice(unique_ventilat),
327
+ )
328
+
329
+ HXCOPD = gr.Radio(
330
+ label="History of COPD",
331
+ choices=unique_hxcopd,
332
+ type='index',
333
+ value=lambda: random.choice(unique_hxcopd),
334
+ )
335
+
336
+ ASCITES = gr.Radio(
337
+ label="Ascites",
338
+ choices=unique_ascites,
339
+ type='index',
340
+ value=lambda: random.choice(unique_ascites),
341
+ )
342
+
343
+ HXCHF = gr.Radio(
344
+ label="History of Congestive Heart Failure",
345
+ choices=unique_hxchf,
346
+ type='index',
347
+ value=lambda: random.choice(unique_hxchf),
348
+ )
349
+
350
+ HYPERMED = gr.Radio(
351
+ label="Hypertension Despite Medication",
352
+ choices=unique_hypermed,
353
+ type='index',
354
+ value=lambda: random.choice(unique_hypermed),
355
+ )
356
+
357
+ RENAFAIL = gr.Radio(
358
+ label="Renal Failure",
359
+ choices=unique_renafail,
360
+ type='index',
361
+ value=lambda: random.choice(unique_renafail),
362
+ )
363
+
364
+ DIALYSIS = gr.Radio(
365
+ label="Dialysis",
366
+ choices=unique_dialysis,
367
+ type='index',
368
+ value=lambda: random.choice(unique_dialysis),
369
+ )
370
+
371
+ STEROID = gr.Radio(
372
+ label="Steroid",
373
+ choices=unique_steroid,
374
+ type='index',
375
+ value=lambda: random.choice(unique_steroid),
376
+ )
377
+
378
+ WTLOSS = gr.Radio(
379
+ label="Weight Loss",
380
+ choices=unique_wtloss,
381
+ type='index',
382
+ value=lambda: random.choice(unique_wtloss),
383
+ )
384
+
385
+ BLEEDDIS = gr.Radio(
386
+ label="Bleeding Disorder",
387
+ choices=unique_bleeddis,
388
+ type='index',
389
+ value=lambda: random.choice(unique_bleeddis),
390
+ )
391
+
392
+ TRANSFUS = gr.Radio(
393
+ label="Transfusion",
394
+ choices=unique_transfus,
395
+ type='index',
396
+ value=lambda: random.choice(unique_transfus),
397
+ )
398
+
399
+ WNDINF = gr.Radio(
400
+ label="Wound Infection",
401
+ choices=unique_wndinf,
402
+ type='index',
403
+ value=lambda: random.choice(unique_wndinf),
404
+ )
405
+
406
+ DISCANCR = gr.Radio(
407
+ label="Disseminated Cancer",
408
+ choices=unique_discancr,
409
+ type='index',
410
+ value=lambda: random.choice(unique_discancr),
411
+ )
412
+
413
+ FNSTATUS2 = gr.Radio(
414
+ label="Functional Status",
415
+ choices=unique_fnstatus2,
416
+ type='index',
417
+ value=lambda: random.choice(unique_fnstatus2),
418
+ )
419
+
420
+ PRSODM = gr.Slider(label="Sodium", minimum=min(x['PRSODM']), maximum=max(x['PRSODM']), step=1, randomize=True)
421
+
422
+ PRBUN = gr.Slider(label="BUN", minimum=min(x['PRBUN']), maximum=max(x['PRBUN']), step=1, randomize=True)
423
+
424
+ PRCREAT = gr.Slider(label="Creatine", minimum=min(x['PRCREAT']),maximum=max(x['PRCREAT']), step=0.1, randomize=True)
425
+
426
+ PRWBC = gr.Slider(label="WBC", minimum=min(x['PRWBC']), maximum=max(x['PRWBC']), step=0.1, randomize=True)
427
+
428
+ PRHCT = gr.Slider(label="Hematocrit", minimum=min(x['PRHCT']), maximum=max(x['PRHCT']), step=0.1, randomize=True)
429
+
430
+ PRPLATE = gr.Slider(label="Platelet", minimum=min(x['PRPLATE']), maximum=max(x['PRPLATE']), step=1, randomize=True)
431
+
432
+ ASACLAS = gr.Radio(
433
+ label="ASA Class",
434
+ choices=unique_asaclas,
435
+ type='index',
436
+ value=lambda: random.choice(unique_asaclas),
437
+
438
+ )
439
+
440
+ LEVELS = gr.Radio(
441
+ label="Levels",
442
+ choices=unique_levels,
443
+ type='index',
444
+ value=lambda: random.choice(unique_levels),
445
+ )
446
+
447
+ with gr.Column():
448
+
449
+ with gr.Row():
450
+ y1_predict_btn_xgb = gr.Button(value="Predict (XGBoost)")
451
+ y1_predict_btn_lgb = gr.Button(value="Predict (LightGBM)")
452
+ y1_predict_btn_cb = gr.Button(value="Predict (CatBoost)")
453
+ y1_predict_btn_rf = gr.Button(value="Predict (Random Forest)")
454
+ label = gr.Label()
455
+
456
+ with gr.Row():
457
+ y1_interpret_btn_xgb = gr.Button(value="Explain (XGBoost)")
458
+ y1_interpret_btn_lgb = gr.Button(value="Explain (LightGBM)")
459
+ y1_interpret_btn_cb = gr.Button(value="Explain (CatBoost)")
460
+ y1_interpret_btn_rf = gr.Button(value="Explain (Random Forest)")
461
+
462
+ plot = gr.Plot()
463
+
464
+ y1_predict_btn_xgb.click(
465
+ y1_predict_xgb,
466
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
467
+ outputs=[label]
468
+ )
469
+
470
+ y1_predict_btn_lgb.click(
471
+ y1_predict_lgb,
472
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
473
+ outputs=[label]
474
+ )
475
+
476
+ y1_predict_btn_cb.click(
477
+ y1_predict_cb,
478
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
479
+ outputs=[label]
480
+ )
481
+
482
+ y1_predict_btn_rf.click(
483
+ y1_predict_rf,
484
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
485
+ outputs=[label]
486
+ )
487
+
488
+ y1_interpret_btn_xgb.click(
489
+ y1_interpret_xgb,
490
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
491
+ outputs=[plot],
492
+ )
493
+
494
+ y1_interpret_btn_lgb.click(
495
+ y1_interpret_lgb,
496
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
497
+ outputs=[plot],
498
+ )
499
+
500
+ y1_interpret_btn_cb.click(
501
+ y1_interpret_cb,
502
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
503
+ outputs=[plot],
504
+ )
505
+
506
+ y1_interpret_btn_rf.click(
507
+ y1_interpret_rf,
508
+ inputs=[SEX, TRANST, AGE, SURGSPEC, HEIGHT, WEIGHT, DIABETES, SMOKE, DYSPNEA, FNSTATUS2, VENTILAT, HXCOPD, ASCITES, HXCHF, HYPERMED, RENAFAIL, DIALYSIS, DISCANCR, WNDINF, STEROID, WTLOSS, BLEEDDIS, TRANSFUS, PRSODM, PRBUN, PRCREAT, PRWBC, PRHCT, PRPLATE, ASACLAS, BMI, RACE, LEVELS,],
509
+ outputs=[plot],
510
+ )
511
+
512
+ demo.launch()