mertkarabacak commited on
Commit
4c90f69
0 Parent(s):

Duplicate from MSHS-Neurosurgery-Research/NSQIP-CDA

Browse files
Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +11 -0
  3. app.py +504 -0
  4. requirements.txt +12 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: NSQIP-CDA
3
+ emoji: 🏢
4
+ colorFrom: pink
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.12.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: MSHS-Neurosurgery-Research/NSQIP-CDA
11
+ ---
app.py ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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', '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.5510926378114541, 'alpha': 2.0796731320109623e-05, 'max_depth': 8, 'eta': 0.7105161360756392, 'gamma': 0.0063548351925993354, 'grow_policy': 'lossguide'}
103
+
104
+ y1_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.00015201438108112603, 'lambda_l2': 1.2678336645891737e-05, 'num_leaves': 201, 'feature_fraction': 0.7349321144466956, 'bagging_fraction': 0.9213936471712818, 'bagging_freq': 2, 'min_child_samples': 27}
105
+
106
+ y1_cb_params = {'objective': 'Logloss', 'colsample_bylevel': 0.08511055529750637, 'depth': 12, 'boosting_type': 'Plain', 'bootstrap_type': 'Bayesian', 'bagging_temperature': 3.571269095878882}
107
+
108
+ y1_rf_params = {'criterion': 'entropy', 'max_features': 'sqrt', 'max_depth': 90, 'n_estimators': 900, '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 {"Adverse Outcomes": float(pos_pred[0]), "No Adverse Outcomes": 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 {"Adverse Outcomes": float(pos_pred[0]), "No Adverse Outcomes": 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 {"Adverse Outcomes": float(pos_pred[0][1]), "No Adverse Outcomes": 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 {"Adverse Outcomes": float(pos_pred[0][1]), "No Adverse Outcomes": 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
+
253
+ with gr.Row():
254
+
255
+ with gr.Column():
256
+
257
+ AGE = gr.Slider(label="Age", minimum=17, maximum=99, step=1, randomize=True)
258
+
259
+ SEX = gr.Radio(
260
+ label="Sex",
261
+ choices=unique_sex,
262
+ type='index',
263
+ value=lambda: random.choice(unique_sex),
264
+ )
265
+
266
+ RACE = gr.Radio(
267
+ label="Race",
268
+ choices=unique_race,
269
+ type='index',
270
+ value=lambda: random.choice(unique_race),
271
+ )
272
+
273
+ HEIGHT = gr.Slider(label="Height (in meters)", minimum=1.0, maximum=2.25, step=0.01, randomize=True)
274
+
275
+ WEIGHT = gr.Slider(label="Weight (in kilograms)", minimum=20, maximum=200, step=1, randomize=True)
276
+
277
+ BMI = gr.Slider(label="BMI", minimum=10, maximum=70, step=1, randomize=True)
278
+
279
+ TRANST = gr.Radio(
280
+ label="Transfer Status",
281
+ choices=unique_transt,
282
+ type='index',
283
+ value=lambda: random.choice(unique_transt),
284
+ )
285
+
286
+ SURGSPEC = gr.Radio(
287
+ label="Surgical Specialty",
288
+ choices=unique_surgspec,
289
+ type='index',
290
+ value=lambda: random.choice(unique_surgspec),
291
+ )
292
+
293
+ SMOKE = gr.Radio(
294
+ label="Smoking Status",
295
+ choices=unique_smoke,
296
+ type='index',
297
+ value=lambda: random.choice(unique_smoke),
298
+ )
299
+
300
+ DIABETES = gr.Radio(
301
+ label="Diabetes",
302
+ choices=unique_diabetes,
303
+ type='index',
304
+ value=lambda: random.choice(unique_diabetes),
305
+ )
306
+
307
+ DYSPNEA = gr.Radio(
308
+ label="Dyspnea",
309
+ choices=unique_dyspnea,
310
+ type='index',
311
+ value=lambda: random.choice(unique_dyspnea),
312
+ )
313
+
314
+ VENTILAT = gr.Radio(
315
+ label="Ventilator Dependency",
316
+ choices=unique_ventilat,
317
+ type='index',
318
+ value=lambda: random.choice(unique_ventilat),
319
+ )
320
+
321
+ HXCOPD = gr.Radio(
322
+ label="History of COPD",
323
+ choices=unique_hxcopd,
324
+ type='index',
325
+ value=lambda: random.choice(unique_hxcopd),
326
+ )
327
+
328
+ ASCITES = gr.Radio(
329
+ label="Ascites",
330
+ choices=unique_ascites,
331
+ type='index',
332
+ value=lambda: random.choice(unique_ascites),
333
+ )
334
+
335
+ HXCHF = gr.Radio(
336
+ label="History of Congestive Heart Failure",
337
+ choices=unique_hxchf,
338
+ type='index',
339
+ value=lambda: random.choice(unique_hxchf),
340
+ )
341
+
342
+ HYPERMED = gr.Radio(
343
+ label="Hypertension Despite Medication",
344
+ choices=unique_hypermed,
345
+ type='index',
346
+ value=lambda: random.choice(unique_hypermed),
347
+ )
348
+
349
+ RENAFAIL = gr.Radio(
350
+ label="Renal Failure",
351
+ choices=unique_renafail,
352
+ type='index',
353
+ value=lambda: random.choice(unique_renafail),
354
+ )
355
+
356
+ DIALYSIS = gr.Radio(
357
+ label="Dialysis",
358
+ choices=unique_dialysis,
359
+ type='index',
360
+ value=lambda: random.choice(unique_dialysis),
361
+ )
362
+
363
+ STEROID = gr.Radio(
364
+ label="Steroid",
365
+ choices=unique_steroid,
366
+ type='index',
367
+ value=lambda: random.choice(unique_steroid),
368
+ )
369
+
370
+ WTLOSS = gr.Radio(
371
+ label="Weight Loss",
372
+ choices=unique_wtloss,
373
+ type='index',
374
+ value=lambda: random.choice(unique_wtloss),
375
+ )
376
+
377
+ BLEEDDIS = gr.Radio(
378
+ label="Bleeding Disorder",
379
+ choices=unique_bleeddis,
380
+ type='index',
381
+ value=lambda: random.choice(unique_bleeddis),
382
+ )
383
+
384
+ TRANSFUS = gr.Radio(
385
+ label="Transfusion",
386
+ choices=unique_transfus,
387
+ type='index',
388
+ value=lambda: random.choice(unique_transfus),
389
+ )
390
+
391
+ WNDINF = gr.Radio(
392
+ label="Wound Infection",
393
+ choices=unique_wndinf,
394
+ type='index',
395
+ value=lambda: random.choice(unique_wndinf),
396
+ )
397
+
398
+ DISCANCR = gr.Radio(
399
+ label="Disseminated Cancer",
400
+ choices=unique_discancr,
401
+ type='index',
402
+ value=lambda: random.choice(unique_discancr),
403
+ )
404
+
405
+ FNSTATUS2 = gr.Radio(
406
+ label="Functional Status",
407
+ choices=unique_fnstatus2,
408
+ type='index',
409
+ value=lambda: random.choice(unique_fnstatus2),
410
+ )
411
+
412
+ PRSODM = gr.Slider(label="Sodium", minimum=min(x['PRSODM']), maximum=max(x['PRSODM']), step=1, randomize=True)
413
+
414
+ PRBUN = gr.Slider(label="BUN", minimum=min(x['PRBUN']), maximum=max(x['PRBUN']), step=1, randomize=True)
415
+
416
+ PRCREAT = gr.Slider(label="Creatine", minimum=min(x['PRCREAT']),maximum=max(x['PRCREAT']), step=0.1, randomize=True)
417
+
418
+ PRWBC = gr.Slider(label="WBC", minimum=min(x['PRWBC']), maximum=max(x['PRWBC']), step=0.1, randomize=True)
419
+
420
+ PRHCT = gr.Slider(label="Hematocrit", minimum=min(x['PRHCT']), maximum=max(x['PRHCT']), step=0.1, randomize=True)
421
+
422
+ PRPLATE = gr.Slider(label="Platelet", minimum=min(x['PRPLATE']), maximum=max(x['PRPLATE']), step=1, randomize=True)
423
+
424
+ ASACLAS = gr.Radio(
425
+ label="ASA Class",
426
+ choices=unique_asaclas,
427
+ type='index',
428
+ value=lambda: random.choice(unique_asaclas),
429
+
430
+ )
431
+
432
+ LEVELS = gr.Radio(
433
+ label="Levels",
434
+ choices=unique_levels,
435
+ type='index',
436
+ value=lambda: random.choice(unique_levels),
437
+ )
438
+
439
+ with gr.Column():
440
+
441
+ with gr.Row():
442
+ y1_predict_btn_xgb = gr.Button(value="Predict (XGBoost)")
443
+ y1_predict_btn_lgb = gr.Button(value="Predict (LightGBM)")
444
+ y1_predict_btn_cb = gr.Button(value="Predict (CatBoost)")
445
+ y1_predict_btn_rf = gr.Button(value="Predict (Random Forest)")
446
+ label = gr.Label()
447
+
448
+ with gr.Row():
449
+ y1_interpret_btn_xgb = gr.Button(value="Explain (XGBoost)")
450
+ y1_interpret_btn_lgb = gr.Button(value="Explain (LightGBM)")
451
+ y1_interpret_btn_cb = gr.Button(value="Explain (CatBoost)")
452
+ y1_interpret_btn_rf = gr.Button(value="Explain (Random Forest)")
453
+
454
+ plot = gr.Plot()
455
+
456
+ y1_predict_btn_xgb.click(
457
+ y1_predict_xgb,
458
+ 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,],
459
+ outputs=[label]
460
+ )
461
+
462
+ y1_predict_btn_lgb.click(
463
+ y1_predict_lgb,
464
+ 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,],
465
+ outputs=[label]
466
+ )
467
+
468
+ y1_predict_btn_cb.click(
469
+ y1_predict_cb,
470
+ 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,],
471
+ outputs=[label]
472
+ )
473
+
474
+ y1_predict_btn_rf.click(
475
+ y1_predict_rf,
476
+ 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,],
477
+ outputs=[label]
478
+ )
479
+
480
+ y1_interpret_btn_xgb.click(
481
+ y1_interpret_xgb,
482
+ 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,],
483
+ outputs=[plot],
484
+ )
485
+
486
+ y1_interpret_btn_lgb.click(
487
+ y1_interpret_lgb,
488
+ 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,],
489
+ outputs=[plot],
490
+ )
491
+
492
+ y1_interpret_btn_cb.click(
493
+ y1_interpret_cb,
494
+ 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,],
495
+ outputs=[plot],
496
+ )
497
+
498
+ y1_interpret_btn_rf.click(
499
+ y1_interpret_rf,
500
+ 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,],
501
+ outputs=[plot],
502
+ )
503
+
504
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ hpsklearn==0.1.0
2
+ sklearn==0.0
3
+ sklearn-contrib-py-earth @ git+https://github.com/scikit-learn-contrib/py-earth.git@dde5f899255411a7b9cbbabf93a817eff4b02e5e
4
+ sklearn-pandas==2.2.0
5
+ matplotlib==3.5.3
6
+ xgboost==1.6.2
7
+ catboost
8
+ lightgbm
9
+ shap==0.41.0
10
+ randomgen==1.23.1
11
+ optuna==3.0.3
12
+ scipy==1.7.3