mertkarabacak commited on
Commit
83012ca
0 Parent(s):

Duplicate from MSHS-Neurosurgery-Research/NSQIP-ACDF

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +584 -0
  4. requirements.txt +12 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.npy filter=lfs diff=lfs merge=lfs -text
14
+ *.npz filter=lfs diff=lfs merge=lfs -text
15
+ *.onnx filter=lfs diff=lfs merge=lfs -text
16
+ *.ot filter=lfs diff=lfs merge=lfs -text
17
+ *.parquet filter=lfs diff=lfs merge=lfs -text
18
+ *.pb filter=lfs diff=lfs merge=lfs -text
19
+ *.pickle filter=lfs diff=lfs merge=lfs -text
20
+ *.pkl filter=lfs diff=lfs merge=lfs -text
21
+ *.pt filter=lfs diff=lfs merge=lfs -text
22
+ *.pth filter=lfs diff=lfs merge=lfs -text
23
+ *.rar filter=lfs diff=lfs merge=lfs -text
24
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
25
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
26
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
27
+ *.tflite filter=lfs diff=lfs merge=lfs -text
28
+ *.tgz filter=lfs diff=lfs merge=lfs -text
29
+ *.wasm filter=lfs diff=lfs merge=lfs -text
30
+ *.xz filter=lfs diff=lfs merge=lfs -text
31
+ *.zip filter=lfs diff=lfs merge=lfs -text
32
+ *.zst filter=lfs diff=lfs merge=lfs -text
33
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
34
+ acdf_final.csv filter=lfs diff=lfs merge=lfs -text
35
+ acdf_imputed.csv filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: NSQIP-ACDF
3
+ emoji: 🏢
4
+ colorFrom: green
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.6
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: MSHS-Neurosurgery-Research/NSQIP-ACDF
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,584 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ HF_TOKEN = os.getenv("HF_TOKEN")
3
+
4
+ import numpy as np
5
+ import pandas as pd
6
+ import sklearn
7
+ import sklearn.metrics
8
+ from math import sqrt
9
+ from scipy import stats as st
10
+ from matplotlib import pyplot as plt
11
+
12
+ from sklearn.linear_model import LogisticRegression
13
+
14
+ import shap
15
+ import gradio as gr
16
+ import random
17
+ import re
18
+ import textwrap
19
+ from datasets import load_dataset
20
+
21
+
22
+ #Read data training data.
23
+
24
+ x1 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="los_data_train.csv", use_auth_token = HF_TOKEN)
25
+ x1 = pd.DataFrame(x1['train'])
26
+ x1 = x1.iloc[:, 1:]
27
+
28
+ x2 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="discharge_data_train.csv", use_auth_token = HF_TOKEN)
29
+ x2 = pd.DataFrame(x2['train'])
30
+ x2 = x2.iloc[:, 1:]
31
+
32
+ x3 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="readmission_data_train.csv", use_auth_token = HF_TOKEN)
33
+ x3 = pd.DataFrame(x3['train'])
34
+ x3 = x3.iloc[:, 1:]
35
+
36
+
37
+ #Read validation data.
38
+
39
+ x1_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="los_data_valid.csv", use_auth_token = HF_TOKEN)
40
+ x1_valid = pd.DataFrame(x1_valid['train'])
41
+ x1_valid = x1_valid.iloc[:, 1:]
42
+
43
+ x2_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="discharge_data_valid.csv", use_auth_token = HF_TOKEN)
44
+ x2_valid = pd.DataFrame(x2_valid['train'])
45
+ x2_valid = x2_valid.iloc[:, 1:]
46
+
47
+ x3_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="readmission_data_valid.csv", use_auth_token = HF_TOKEN)
48
+ x3_valid = pd.DataFrame(x3_valid['train'])
49
+ x3_valid = x3_valid.iloc[:, 1:]
50
+
51
+ #Define feature names.
52
+ f1_names = list(x1.columns)
53
+ f1_names = [f1.replace('__', ' - ') for f1 in f1_names]
54
+ f1_names = [f1.replace('_', ' ') for f1 in f1_names]
55
+
56
+ f2_names = list(x2.columns)
57
+ f2_names = [f2.replace('__', ' - ') for f2 in f2_names]
58
+ f2_names = [f2.replace('_', ' ') for f2 in f2_names]
59
+
60
+ f3_names = list(x3.columns)
61
+ f3_names = [f3.replace('__', ' - ') for f3 in f3_names]
62
+ f3_names = [f3.replace('_', ' ') for f3 in f3_names]
63
+
64
+ #Assign unique values as answer options.
65
+
66
+ unique_SEX = ['Male', 'Female', 'Non-binary']
67
+ unique_RACE = ['White', 'Black or African American', 'Asian', 'American Indian or Alaska Native', 'Native Hawaiian or Pacific Islander', 'Other/Unknown']
68
+ unique_ETHNICITY = ['No', 'Yes', 'Unknown']
69
+ unique_TRANSFER = ['Not transferred', 'Transferred', 'Unknown']
70
+ unique_SMOKER = ['No', 'Yes', 'Unknown']
71
+ unique_DIABETES = ['No', 'Yes', 'Unknown']
72
+ unique_DYSPNEA = ['No', 'Yes']
73
+ unique_VENTILATOR = ['No', 'Yes']
74
+ unique_COPD = ['No', 'Yes']
75
+ unique_ASCITES = ['No', 'Yes']
76
+ unique_CHF = ['No', 'Yes']
77
+ unique_HTN = ['No', 'Yes']
78
+ unique_ARF = ['No', 'Yes']
79
+ unique_DIALYSIS = ['No', 'Yes']
80
+ unique_CANCER = ['No', 'Yes']
81
+ unique_WOUND = ['No', 'Yes']
82
+ unique_STEROID = ['No', 'Yes']
83
+ unique_MALNOURISH = ['No', 'Yes']
84
+ unique_BLEEDING = ['No', 'Yes']
85
+ unique_TRANSFUSION = ['No', 'Yes']
86
+ unique_ASA = ['1-No Disturb', '2-Mild Disturb', '3-Severe Disturb']
87
+ unique_FUNCTIONAL = ['Independent', 'Partially Dependent', 'Totally Dependent', 'Unknown']
88
+ unique_SPECIALTY = ['Neurosurgery', 'Orthopedics']
89
+ unique_LEVELS = ['Single', 'Multiple']
90
+
91
+
92
+ #Prepare training data for the outcome 1 (mortality).
93
+ y1 = x1.pop('OUTCOME')
94
+
95
+ #Prepare validation data for the outcome 1 (mortality).
96
+ y1_valid = x1_valid.pop('OUTCOME')
97
+
98
+ #Prepare training data for the outcome 2 (discharge).
99
+ y2 = x2.pop('OUTCOME')
100
+
101
+ #Prepare validation data for the outcome 2 (discharge).
102
+ y2_valid = x2_valid.pop('OUTCOME')
103
+
104
+ #Prepare training data for the outcome 3 (LOS).
105
+ y3 = x3.pop('OUTCOME')
106
+
107
+ #Prepare validation data for the outcome 3 (LOS).
108
+ y3_valid = x3_valid.pop('OUTCOME')
109
+
110
+
111
+ #Assign hyperparameters.
112
+
113
+ y1_params = {'criterion': 'gini', 'max_features': 'sqrt', 'max_depth': 71, 'n_estimators': 700, 'min_samples_leaf': 1, 'min_samples_split': 5, 'random_state': 31}
114
+ y2_params = {'criterion': 'gini', 'max_features': 'log2', 'max_depth': 71, 'n_estimators': 100, 'min_samples_leaf': 1, 'min_samples_split': 2, 'random_state': 31}
115
+ y3_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.00011911004377577721, 'lambda_l2': 1.4114822246196016e-08, 'num_leaves': 255, 'feature_fraction': 0.5994245138163354, 'bagging_fraction': 0.9778102858951696, 'bagging_freq': 4, 'min_child_samples': 6, 'metric': 'binary_logloss', 'verbosity': -1, 'random_state': 31}
116
+
117
+
118
+ #Training models.
119
+ from sklearn.ensemble import RandomForestClassifier
120
+ rf = RandomForestClassifier(**y1_params)
121
+ y1_model = rf
122
+
123
+ y1_model = y1_model.fit(x1, y1)
124
+ y1_explainer = shap.Explainer(y1_model.predict, x1.values)
125
+ y1_calib_probs = y1_model.predict_proba(x1_valid)
126
+ y1_calib_model = LogisticRegression()
127
+ y1_calib_model = y1_calib_model.fit(y1_calib_probs, y1_valid)
128
+
129
+
130
+ from sklearn.ensemble import RandomForestClassifier
131
+ rf = RandomForestClassifier(**y2_params)
132
+ y2_model = rf
133
+
134
+ y2_model = y2_model.fit(x2, y2)
135
+ y2_explainer = shap.Explainer(y2_model.predict, x2.values)
136
+ y2_calib_probs = y2_model.predict_proba(x2_valid)
137
+ y2_calib_model = LogisticRegression()
138
+ y2_calib_model = y2_calib_model.fit(y2_calib_probs, y2_valid)
139
+
140
+
141
+ from lightgbm import LGBMClassifier
142
+ lgb = LGBMClassifier(**y3_params)
143
+ y3_model = lgb
144
+
145
+ y3_model = y3_model.fit(x3, y3)
146
+ y3_explainer = shap.Explainer(y3_model.predict, x3.values)
147
+ y3_calib_probs = y3_model.predict_proba(x3_valid)
148
+ y3_calib_model = LogisticRegression()
149
+ y3_calib_model = y3_calib_model.fit(y3_calib_probs, y3_valid)
150
+
151
+
152
+ output_y1 = (
153
+ """
154
+ <br/>
155
+ <center>The predicted risk of prolonged length of stay:</center>
156
+ <br/>
157
+ <center><h1>{:.2f}%</h1></center>
158
+ """
159
+ )
160
+
161
+ output_y2 = (
162
+ """
163
+ <br/>
164
+ <center>The predicted risk of non-home discharge:</center>
165
+ <br/>
166
+ <center><h1>{:.2f}%</h1></center>
167
+ """
168
+ )
169
+
170
+ output_y3 = (
171
+ """
172
+ <br/>
173
+ <center>The predicted risk of 30-day readmission:</center>
174
+ <br/>
175
+ <center><h1>{:.2f}%</h1></center>
176
+ """
177
+ )
178
+
179
+
180
+ #Define predict for y1.
181
+ def y1_predict(*args):
182
+ df1 = pd.DataFrame([args], columns=x1.columns)
183
+ pos_pred = y1_model.predict_proba(df1)
184
+ pos_pred = y1_calib_model.predict_proba(pos_pred)
185
+ prob = pos_pred[0][1]
186
+ output = output_y1.format(prob * 100)
187
+ return output
188
+
189
+ #Define predict for y2.
190
+ def y2_predict(*args):
191
+ df2 = pd.DataFrame([args], columns=x2.columns)
192
+ pos_pred = y2_model.predict_proba(df2)
193
+ pos_pred = y2_calib_model.predict_proba(pos_pred)
194
+ prob = pos_pred[0][1]
195
+ output = output_y2.format(prob * 100)
196
+ return output
197
+
198
+ #Define predict for y3.
199
+ def y3_predict(*args):
200
+ df3 = pd.DataFrame([args], columns=x3.columns)
201
+ pos_pred = y3_model.predict_proba(df3)
202
+ pos_pred = y3_calib_model.predict_proba(pos_pred)
203
+ prob = pos_pred[0][1]
204
+ output = output_y3.format(prob * 100)
205
+ return output
206
+
207
+
208
+ #Define function for wrapping feature labels.
209
+ def wrap_labels(ax, width, break_long_words=False):
210
+ labels = []
211
+ for label in ax.get_yticklabels():
212
+ text = label.get_text()
213
+ labels.append(textwrap.fill(text, width=width, break_long_words=break_long_words))
214
+ ax.set_yticklabels(labels, rotation=0)
215
+
216
+
217
+ #Define interpret for y1 (prolonged LOS).
218
+ def y1_interpret(*args):
219
+ df1 = pd.DataFrame([args], columns=x1.columns)
220
+ shap_values1 = y1_explainer(df1).values
221
+ shap_values1 = np.abs(shap_values1)
222
+ shap.bar_plot(shap_values1[0], max_display = 10, show = False, feature_names = f1_names)
223
+ fig = plt.gcf()
224
+ ax = plt.gca()
225
+ wrap_labels(ax, 20)
226
+ ax.figure
227
+ plt.tight_layout()
228
+ fig.set_figheight(7)
229
+ fig.set_figwidth(9)
230
+ plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
231
+ plt.tick_params(axis="y",direction="out", labelsize = 12)
232
+ plt.tick_params(axis="x",direction="out", labelsize = 12)
233
+ return fig
234
+
235
+ #Define interpret for y2 (non-home discharges).
236
+ def y2_interpret(*args):
237
+ df2 = pd.DataFrame([args], columns=x2.columns)
238
+ shap_values2 = y2_explainer(df2).values
239
+ shap_values2 = np.abs(shap_values2)
240
+ shap.bar_plot(shap_values2[0], max_display = 10, show = False, feature_names = f2_names)
241
+ fig = plt.gcf()
242
+ ax = plt.gca()
243
+ wrap_labels(ax, 20)
244
+ ax.figure
245
+ plt.tight_layout()
246
+ fig.set_figheight(7)
247
+ fig.set_figwidth(9)
248
+ plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
249
+ plt.tick_params(axis="y",direction="out", labelsize = 12)
250
+ plt.tick_params(axis="x",direction="out", labelsize = 12)
251
+ return fig
252
+
253
+ #Define interpret for y3 (30-day readmissions).
254
+ def y3_interpret(*args):
255
+ df3 = pd.DataFrame([args], columns=x3.columns)
256
+ shap_values3 = y3_explainer(df3).values
257
+ shap_values3 = np.abs(shap_values3)
258
+ shap.bar_plot(shap_values3[0], max_display = 10, show = False, feature_names = f3_names)
259
+ fig = plt.gcf()
260
+ ax = plt.gca()
261
+ wrap_labels(ax, 20)
262
+ ax.figure
263
+ plt.tight_layout()
264
+ fig.set_figheight(7)
265
+ fig.set_figwidth(9)
266
+ plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
267
+ plt.tick_params(axis="y",direction="out", labelsize = 12)
268
+ plt.tick_params(axis="x",direction="out", labelsize = 12)
269
+ return fig
270
+
271
+
272
+ with gr.Blocks(title = "NSQIP-ACDF") as demo:
273
+
274
+ gr.Markdown(
275
+ """
276
+ <br/>
277
+ <center><h1>ACDF Outcomes</h1></center>
278
+ <center><h2>Prediction Tool</h2></center>
279
+ <center><i>The publication describing the details of this predictive tool will be posted here upon the acceptance of publication.</i><center>
280
+ """
281
+ )
282
+
283
+ gr.Markdown(
284
+ """
285
+ <center><h3>Model Performances</h3></center>
286
+ <div style="text-align:center;">
287
+ <table>
288
+ <tr>
289
+ <th>Outcome</th>
290
+ <th>Algorithm</th>
291
+ <th>Weighted Precision</th>
292
+ <th>Weighted Recall</th>
293
+ <th>Weighted AUPRC</th>
294
+ <th>Balanced Accuracy</th>
295
+ <th>AUROC</th>
296
+ <th>Brier Score</th>
297
+ </tr>
298
+ <tr>
299
+ <td>Prolonged LOS</td>
300
+ <td>Random Forest</td>
301
+ <td>0.874 (0.868 - 0.880)</td>
302
+ <td>0.689 (0.681 - 0.697)</td>
303
+ <td>0.495 (0.486 - 0.504)</td>
304
+ <td>0.703 (0.695 - 0.711)</td>
305
+ <td>0.805 (0.777 - 0.806)</td>
306
+ <td>0.076 (0.071 - 0.081)</td>
307
+ </tr>
308
+ <tr>
309
+ <td>Non-home Discharges</td>
310
+ <td>Random Forest</td>
311
+ <td>0.961 (0.957 - 0.965)</td>
312
+ <td>0.737 (0.729 - 0.745)</td>
313
+ <td>0.239 (0.231 - 0.247)</td>
314
+ <td>0.753 (0.745 - 0.761)</td>
315
+ <td>0.815 (0.801 - 0.847)</td>
316
+ <td>0.028 (0.025 - 0.031)</td>
317
+ </tr>
318
+ <tr>
319
+ <td>Prolonged LOS</td>
320
+ <td>LightGBM</td>
321
+ <td>0.961 (0.957 - 0.965)</td>
322
+ <td>0.634 (0.625 - 0.643)</td>
323
+ <td>0.171 (0.164 - 0.178)</td>
324
+ <td>0.666 (0.657 - 0.675)</td>
325
+ <td>0.760 (0.711 - 0.774)</td>
326
+ <td>0.026 (0.023 - 0.029)</td>
327
+ </tr>
328
+ </table>
329
+ </div>
330
+ """
331
+ )
332
+
333
+ with gr.Row():
334
+
335
+ with gr.Column():
336
+
337
+ Age = gr.Slider(label="Age", minimum = 18, maximum = 99, step = 1, value = 55)
338
+
339
+ Sex = gr.Radio(label = "Sex", choices = unique_SEX, type = 'index', value = 'Female')
340
+
341
+ Race = gr.Radio(label = "Race", choices = unique_RACE, type = 'index', value = 'White')
342
+
343
+ Hispanic_Ethnicity = gr.Radio(label = "Hispanic Ethnicity", choices = unique_ETHNICITY, type = 'index', value = 'No')
344
+
345
+ Height = gr.Slider(label = "Height (in centimeters)", minimum = 100, maximum = 250, step = 1, value = 175)
346
+
347
+ Weight = gr.Slider(label = "Weight (in kilograms)", minimum = 20, maximum = 200, step = 1, value = 75)
348
+
349
+ Transfer_Status = gr.Radio(label = "Transfer Status", choices = unique_TRANSFER, type = 'index', value = 'Not transferred')
350
+
351
+ Current_Smoker_Status = gr.Radio(label = "Current Smoker Status", choices = unique_SMOKER, type = 'index', value = 'No')
352
+
353
+ Diabetes_Mellitus_Requiring_Therapy = gr.Radio(label = "Diabetes Mellitus Requiring Therapy", choices = unique_DIABETES, type = 'index', value = 'No')
354
+
355
+ Dyspnea = gr.Radio(label = "Dyspnea", choices = unique_DYSPNEA, type = 'index', value = 'No')
356
+
357
+ Ventilator_Dependency = gr.Radio(label = "Ventilator Dependency", choices = unique_VENTILATOR, type = 'index', value = 'No')
358
+
359
+ History_of_Severe_COPD = gr.Radio(label = "History of Severe COPD", choices = unique_COPD, type = 'index', value = 'No')
360
+
361
+ Ascites_within_30_Days_Prior_to_Surgery = gr.Radio(label = "Ascites within 30 Days Prior to Surgery", choices = unique_ASCITES, type = 'index', value = 'No')
362
+
363
+ Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery = gr.Radio(label = "Congestive Heart Failure within 30 Days Prior to Surgery", choices = unique_CHF, type = 'index', value = 'No')
364
+
365
+ Hypertension_Requiring_Medication = gr.Radio(label = "Hypertension Requiring Medication", choices = unique_HTN, type = 'index', value = 'No')
366
+
367
+ Acute_Renal_Failure = gr.Radio(label = "Acute Renal Failure", choices = unique_ARF, type = 'index', value = 'No')
368
+
369
+ Currently_Requiring_or_on_Dialysis = gr.Radio(label = "Currently Requiring or on Dialysis", choices = unique_DIALYSIS, type = 'index', value = 'No')
370
+
371
+ Disseminated_Cancer = gr.Radio(label = "Disseminated Cancer", choices = unique_CANCER, type = 'index', value = 'No')
372
+
373
+ Open_Wound = gr.Radio(label = "Open Wound", choices = unique_WOUND, type = 'index', value = 'No')
374
+
375
+ Steroid_Immunosuppressant_for_a_Chronic_Condition = gr.Radio(label = "Steroid/Immunosuppressant for a Chronic Condition", choices = unique_STEROID, type = 'index', value = 'No')
376
+
377
+ Malnourishment = gr.Radio(label = "Malnourishment", choices = unique_MALNOURISH, type = 'index', value = 'No')
378
+
379
+ Bleeding_Disorder = gr.Radio(label = "Bleeding Disorder", choices = unique_BLEEDING, type = 'index', value = 'No')
380
+
381
+ RBC_Transfusion_within_72_Hours_Prior_to_Surgery = gr.Radio(label = "RBC Transfusion within 72 Hours Prior to Surgery", choices = unique_TRANSFUSION, type = 'index', value = 'No')
382
+
383
+ ASA_Classification = gr.Radio(label = "ASA Classification", choices = unique_ASA, type = 'index', value = '1-No Disturb')
384
+
385
+ Functional_Status = gr.Radio(label = "Functional_Status", choices = unique_FUNCTIONAL, type = 'index', value = 'Independent')
386
+
387
+ Preoperative_Serum_Sodium = gr.Slider(label="Preoperative Serum Sodium", minimum = 110, maximum = 150, step = 1, value = 135)
388
+
389
+ Preoperative_Serum_BUN = gr.Slider(label="Preoperative Serum BUN", minimum = 0, maximum = 100, step = 1, value = 15)
390
+
391
+ Preoperative_Serum_Creatinine = gr.Slider(label="Preoperative Serum Creatinine", minimum = 0, maximum = 20, step = 0.1, value = 0.9)
392
+
393
+ Preoperative_WBC_Count = gr.Slider(label="Preoperative WBC Count (x1000)", minimum = 1, maximum = 50, step = 0.1, value = 5)
394
+
395
+ Preoperative_Hematocrit = gr.Slider(label="Preoperative Hematocrit", minimum = 20, maximum = 70, step = 0.1, value = 45)
396
+
397
+ Preoperative_Platelet_Count = gr.Slider(label="Preoperative Platelet Count (x1000)", minimum = 50, maximum = 1000, step = 1, value = 250)
398
+
399
+ Surgical_Specialty = gr.Radio(label = "Surgical Specialty", choices = unique_SPECIALTY, type = 'index', value = 'Neurosurgery')
400
+
401
+ Single_or_Multiple_Level_Surgery = gr.Radio(label = "Single or Multiple Level Surgery", choices = unique_LEVELS, type = 'index', value = 'Single')
402
+
403
+
404
+ with gr.Column():
405
+
406
+ with gr.Box():
407
+
408
+ gr.Markdown(
409
+ """
410
+ <center> <h2>Prolonged Length of Stay</h2> </center>
411
+ <center> This model uses the Random Forest algorithm.</center>
412
+ <br/>
413
+ """
414
+ )
415
+
416
+ with gr.Row():
417
+ y1_predict_btn = gr.Button(value="Predict")
418
+
419
+ gr.Markdown(
420
+ """
421
+ <br/>
422
+ """
423
+ )
424
+
425
+ label1 = gr.Markdown()
426
+
427
+ gr.Markdown(
428
+ """
429
+ <br/>
430
+ """
431
+ )
432
+
433
+ with gr.Row():
434
+ y1_interpret_btn = gr.Button(value="Explain")
435
+
436
+ gr.Markdown(
437
+ """
438
+ <br/>
439
+ """
440
+ )
441
+
442
+ plot1 = gr.Plot()
443
+
444
+ gr.Markdown(
445
+ """
446
+ <br/>
447
+ """
448
+ )
449
+
450
+ with gr.Box():
451
+ gr.Markdown(
452
+ """
453
+ <center> <h2>Non-home Discharges</h2> </center>
454
+ <center> This model uses the Random Forest algorithm.</center>
455
+ <br/>
456
+ """
457
+ )
458
+
459
+ with gr.Row():
460
+ y2_predict_btn = gr.Button(value="Predict")
461
+
462
+ gr.Markdown(
463
+ """
464
+ <br/>
465
+ """
466
+ )
467
+
468
+ label2 = gr.Markdown()
469
+
470
+ gr.Markdown(
471
+ """
472
+ <br/>
473
+ """
474
+ )
475
+
476
+ with gr.Row():
477
+ y2_interpret_btn = gr.Button(value="Explain")
478
+
479
+ gr.Markdown(
480
+ """
481
+ <br/>
482
+ """
483
+ )
484
+
485
+ plot2 = gr.Plot()
486
+
487
+ gr.Markdown(
488
+ """
489
+ <br/>
490
+ """
491
+ )
492
+
493
+ with gr.Box():
494
+
495
+ gr.Markdown(
496
+ """
497
+ <center> <h2>30-day Readmissions</h2> </center>
498
+ <center> This model uses the LightGBM algorithm.</center>
499
+ <br/>
500
+ """
501
+ )
502
+
503
+ with gr.Row():
504
+ y3_predict_btn = gr.Button(value="Predict")
505
+
506
+ gr.Markdown(
507
+ """
508
+ <br/>
509
+ """
510
+ )
511
+
512
+ label3 = gr.Markdown()
513
+
514
+ gr.Markdown(
515
+ """
516
+ <br/>
517
+ """
518
+ )
519
+
520
+ with gr.Row():
521
+ y3_interpret_btn = gr.Button(value="Explain")
522
+
523
+ gr.Markdown(
524
+ """
525
+ <br/>
526
+ """
527
+ )
528
+
529
+ plot3 = gr.Plot()
530
+
531
+ gr.Markdown(
532
+ """
533
+ <br/>
534
+ """
535
+ )
536
+
537
+ y1_predict_btn.click(
538
+ y1_predict,
539
+ inputs = [Age, Sex, Race, Hispanic_Ethnicity, Height, Weight, Transfer_Status, Current_Smoker_Status, Diabetes_Mellitus_Requiring_Therapy, Dyspnea, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, ASA_Classification, Functional_Status, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, Surgical_Specialty, Single_or_Multiple_Level_Surgery,],
540
+ outputs = [label1]
541
+ )
542
+
543
+ y2_predict_btn.click(
544
+ y2_predict,
545
+ inputs = [Age, Sex, Race, Hispanic_Ethnicity, Height, Weight, Transfer_Status, Current_Smoker_Status, Diabetes_Mellitus_Requiring_Therapy, Dyspnea, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, ASA_Classification, Functional_Status, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, Surgical_Specialty, Single_or_Multiple_Level_Surgery,],
546
+ outputs = [label2]
547
+ )
548
+
549
+ y3_predict_btn.click(
550
+ y3_predict,
551
+ inputs = [Age, Sex, Race, Hispanic_Ethnicity, Height, Weight, Transfer_Status, Current_Smoker_Status, Diabetes_Mellitus_Requiring_Therapy, Dyspnea, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, ASA_Classification, Functional_Status, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, Surgical_Specialty, Single_or_Multiple_Level_Surgery,],
552
+ outputs = [label3]
553
+ )
554
+
555
+ y1_interpret_btn.click(
556
+ y1_interpret,
557
+ inputs = [Age, Sex, Race, Hispanic_Ethnicity, Height, Weight, Transfer_Status, Current_Smoker_Status, Diabetes_Mellitus_Requiring_Therapy, Dyspnea, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, ASA_Classification, Functional_Status, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, Surgical_Specialty, Single_or_Multiple_Level_Surgery,],
558
+ outputs = [plot1],
559
+ )
560
+
561
+ y2_interpret_btn.click(
562
+ y2_interpret,
563
+ inputs = [Age, Sex, Race, Hispanic_Ethnicity, Height, Weight, Transfer_Status, Current_Smoker_Status, Diabetes_Mellitus_Requiring_Therapy, Dyspnea, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, ASA_Classification, Functional_Status, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, Surgical_Specialty, Single_or_Multiple_Level_Surgery,],
564
+ outputs = [plot2],
565
+ )
566
+
567
+ y3_interpret_btn.click(
568
+ y3_interpret,
569
+ inputs = [Age, Sex, Race, Hispanic_Ethnicity, Height, Weight, Transfer_Status, Current_Smoker_Status, Diabetes_Mellitus_Requiring_Therapy, Dyspnea, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, Congestive_Heart_Failure_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, ASA_Classification, Functional_Status, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, Surgical_Specialty, Single_or_Multiple_Level_Surgery,],
570
+ outputs = [plot3],
571
+ )
572
+
573
+ gr.Markdown(
574
+ """
575
+ <center><h2>Disclaimer</h2>
576
+ <center>
577
+ 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. 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. 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. 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. 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.
578
+ <br/>
579
+ <h4>By using this tool, you accept all of the above terms.<h4/>
580
+ </center>
581
+ """
582
+ )
583
+
584
+ 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