mertkarabacak mertkarabacak commited on
Commit
776982c
·
0 Parent(s):

Duplicate from MSHS-Neurosurgery-Research/NSQIP-PLF

Browse files

Co-authored-by: Mert Karabacak <mertkarabacak@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +11 -0
  3. app.py +1291 -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,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: NSQIP-PLF
3
+ emoji: 🏢
4
+ colorFrom: gray
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.6
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: MSHS-Neurosurgery-Research/NSQIP-PLF
11
+ ---
app.py ADDED
@@ -0,0 +1,1291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-PLF", data_files="plf_imputed.csv", use_auth_token = HF_TOKEN)
37
+
38
+ data = pd.DataFrame(data['train'])
39
+ variables = ['SEX', 'INOUT', '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', 'LOS', 'DISCHARGE']
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('LOS')
51
+ y2 = data.pop('DISCHARGE')
52
+ y3 = data.pop('READMISSION1')
53
+ y1 = (y1 == "Yes").astype(int)
54
+ y2 = (y2 == "Yes").astype(int)
55
+ y3 = (y3 == "Yes").astype(int)
56
+
57
+ categorical_columns = list(x.select_dtypes('object').columns)
58
+
59
+ x = x.astype({col: "category" for col in categorical_columns})
60
+
61
+ #Prepare data for LOS (y1).
62
+ y1_data_xgb = xgb.DMatrix(x, label=y1, enable_categorical=True)
63
+ y1_data_lgb = lgb.Dataset(x, label=y1)
64
+ y1_data_cb = Pool(data=x, label=y1, cat_features=categorical_columns)
65
+
66
+ #Prepare data for DISCHARGE (y2).
67
+ y2_data_xgb = xgb.DMatrix(x, label=y2, enable_categorical=True)
68
+ y2_data_lgb = lgb.Dataset(x, label=y2)
69
+ y2_data_cb = Pool(data=x, label=y2, cat_features=categorical_columns)
70
+
71
+ #Prepare data for READMISSION (y3).
72
+ y3_data_xgb = xgb.DMatrix(x, label=y3, enable_categorical=True)
73
+ y3_data_lgb = lgb.Dataset(x, label=y3)
74
+ y3_data_cb = Pool(data=x, label=y3, cat_features=categorical_columns)
75
+
76
+ #Prepare data for Random Forest models.
77
+ x_rf = x
78
+ categorical_columns = list(x_rf.select_dtypes('category').columns)
79
+ x_rf = x_rf.astype({col: "category" for col in categorical_columns})
80
+ le = sklearn.preprocessing.LabelEncoder()
81
+ for col in categorical_columns:
82
+ x_rf[col] = le.fit_transform(x_rf[col].astype(str))
83
+ d1 = dict.fromkeys(x_rf.select_dtypes(np.int64).columns, str)
84
+ x_rf = x_rf.astype(d1)
85
+
86
+ #Assign unique values as answer options.
87
+
88
+ unique_sex = ['Male', 'Female']
89
+ unique_inout = ['Outpatient', 'Inpatient']
90
+ unique_transt = ['Not Transferred', 'Transferred']
91
+ unique_surgspec = ['Neurosurgery', 'Orthopedics']
92
+ unique_diabetes = ['No', 'Yes']
93
+ unique_smoke = ['No', 'Yes']
94
+ unique_dyspnea = ['No', 'Yes']
95
+ unique_fnstatus2 = ['Independent', 'Partially Dependent', 'Totally Dependent', 'Unknown']
96
+ unique_ventilat = ['No', 'Yes']
97
+ unique_hxcopd = ['No', 'Yes']
98
+ unique_ascites = ['No', 'Yes']
99
+ unique_hxchf = ['No', 'Yes']
100
+ unique_hypermed = ['No', 'Yes']
101
+ unique_renafail = ['No', 'Yes']
102
+ unique_dialysis = ['No', 'Yes']
103
+ unique_discancr = ['No', 'Yes']
104
+ unique_wndinf = ['No', 'Yes']
105
+ unique_steroid = ['No', 'Yes']
106
+ unique_wtloss = ['No', 'Yes']
107
+ unique_bleeddis = ['No', 'Yes']
108
+ unique_transfus = ['No', 'Yes']
109
+ unique_asaclas = ['1-No Disturb', '2-Mild Disturb','3-Severe Disturb']
110
+ unique_race = ['White', 'Black or African American', 'Hispanic', 'Asian', 'Other', 'Unknown']
111
+ unique_levels = ['Single', 'Multiple']
112
+
113
+
114
+ #Assign hyperparameters.
115
+
116
+ y1_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 0.0005339267129552805, 'alpha': 0.0002962624636897887, 'max_depth': 5, 'eta': 0.17974463946440886, 'gamma': 1.955720731101234e-05, 'grow_policy': 'depthwise'}
117
+ y2_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 2.3651795227170203e-07, 'alpha': 2.465112299158626e-07, 'max_depth': 8, 'eta': 0.2016812333750978, 'gamma': 1.9072531571694956e-08, 'grow_policy': 'lossguide'}
118
+ y3_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 3.9182180074030555e-05, 'alpha': 3.7622090080846917e-06, 'max_depth': 9, 'eta': 0.34884518185962, 'gamma': 0.003045967534081103, 'grow_policy': 'depthwise'}
119
+
120
+ y1_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.007709569546582118, 'lambda_l2': 0.3386728384875079, 'num_leaves': 187, 'feature_fraction': 0.6292732071397759, 'bagging_fraction': 0.9756997529130697, 'bagging_freq': 4, 'min_child_samples': 10}
121
+ y2_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 1.3688333191815587e-06, 'lambda_l2': 0.052511051903638244, 'num_leaves': 205, 'feature_fraction': 0.5865629820653324, 'bagging_fraction': 0.9571048929526229, 'bagging_freq': 4, 'min_child_samples': 5}
122
+ y3_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 2.1265290416768583e-05, 'lambda_l2': 0.0018014878119387177, 'num_leaves': 192, 'feature_fraction': 0.8493327170839868, 'bagging_fraction': 0.8945035345315162, 'bagging_freq': 5, 'min_child_samples': 6}
123
+
124
+ y1_cb_params = {'objective': 'Logloss', 'colsample_bylevel': 0.06756293020840613, 'depth': 12, 'boosting_type': 'Plain', 'bootstrap_type': 'Bernoulli', 'subsample': 0.2396438345614389}
125
+ y2_cb_params = {'objective': 'CrossEntropy', 'colsample_bylevel': 0.0973566655789677, 'depth': 10, 'boosting_type': 'Ordered', 'bootstrap_type': 'MVS'}
126
+ y3_cb_params = {'objective': 'Logloss', 'colsample_bylevel': 0.08817565012542608, 'depth': 11, 'boosting_type': 'Plain', 'bootstrap_type': 'MVS'}
127
+
128
+ y1_rf_params = {'criterion': 'entropy', 'max_features': 'log2', 'max_depth': 75, 'n_estimators': 1800, 'min_samples_leaf': 1, 'min_samples_split': 10}
129
+ y2_rf_params = {'criterion': 'gini', 'max_features': 'log2', 'max_depth': 88, 'n_estimators': 1900, 'min_samples_leaf': 1, 'min_samples_split': 9}
130
+ y3_rf_params = {'criterion': 'entropy', 'max_features': 'log2', 'max_depth': 78, 'n_estimators': 1500, 'min_samples_leaf': 4, 'min_samples_split': 6}
131
+
132
+
133
+ #Modeling for y1/LOS.
134
+
135
+ y1_model_xgb = xgb.train(params=y1_xgb_params, dtrain=y1_data_xgb)
136
+ y1_explainer_xgb = shap.TreeExplainer(y1_model_xgb)
137
+
138
+ y1_model_lgb = lgb.train(params=y1_lgb_params, train_set=y1_data_lgb)
139
+ y1_explainer_lgb = shap.TreeExplainer(y1_model_lgb)
140
+
141
+ y1_model_cb = cb.train(pool=y1_data_cb, params=y1_cb_params)
142
+ y1_explainer_cb = shap.TreeExplainer(y1_model_cb)
143
+
144
+ from sklearn.ensemble import RandomForestClassifier as rf
145
+ y1_rf = rf(**y1_rf_params)
146
+ y1_model_rf = y1_rf.fit(x_rf, y1)
147
+ y1_explainer_rf = shap.TreeExplainer(y1_model_rf)
148
+
149
+
150
+ #Modeling for y2/DISCHARGE.
151
+
152
+ y2_model_xgb = xgb.train(params=y2_xgb_params, dtrain=y2_data_xgb)
153
+ y2_explainer_xgb = shap.TreeExplainer(y2_model_xgb)
154
+
155
+ y2_model_lgb = lgb.train(params=y2_lgb_params, train_set=y2_data_lgb)
156
+ y2_explainer_lgb = shap.TreeExplainer(y2_model_lgb)
157
+
158
+ y2_model_cb = cb.train(pool=y2_data_cb, params=y2_cb_params)
159
+ y2_explainer_cb = shap.TreeExplainer(y2_model_cb)
160
+
161
+ from sklearn.ensemble import RandomForestClassifier as rf
162
+ y2_rf = rf(**y2_rf_params)
163
+ y2_model_rf = y2_rf.fit(x_rf, y2)
164
+ y2_explainer_rf = shap.TreeExplainer(y2_model_rf)
165
+
166
+
167
+ #Modeling for y3/READMISSION.
168
+
169
+ y3_model_xgb = xgb.train(params=y3_xgb_params, dtrain=y3_data_xgb)
170
+ y3_explainer_xgb = shap.TreeExplainer(y3_model_xgb)
171
+
172
+ y3_model_lgb = lgb.train(params=y3_lgb_params, train_set=y3_data_lgb)
173
+ y3_explainer_lgb = shap.TreeExplainer(y3_model_lgb)
174
+
175
+ y3_model_cb = cb.train(pool=y3_data_cb, params=y3_cb_params)
176
+ y3_explainer_cb = shap.TreeExplainer(y3_model_cb)
177
+
178
+ from sklearn.ensemble import RandomForestClassifier as rf
179
+ y3_rf = rf(**y3_rf_params)
180
+ y3_model_rf = y3_rf.fit(x_rf, y3)
181
+ y3_explainer_rf = shap.TreeExplainer(y3_model_rf)
182
+
183
+
184
+ #Define predict for y1/LOS.
185
+
186
+ def y1_predict_xgb(*args):
187
+ df_xgb = pd.DataFrame([args], columns=x.columns)
188
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns})
189
+ pos_pred = y1_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
190
+ return {"Prolonged LOS": float(pos_pred[0]), "Not Prolonged LOS": 1 - float(pos_pred[0])}
191
+
192
+ def y1_predict_lgb(*args):
193
+ df = pd.DataFrame([args], columns=data.columns)
194
+ df = df.astype({col: "category" for col in categorical_columns})
195
+ pos_pred = y1_model_lgb.predict(df)
196
+ return {"Prolonged LOS": float(pos_pred[0]), "Not Prolonged LOS": 1 - float(pos_pred[0])}
197
+
198
+ def y1_predict_cb(*args):
199
+ df_cb = pd.DataFrame([args], columns=x.columns)
200
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns})
201
+ pos_pred = y1_model_cb.predict(Pool(df_cb, cat_features = categorical_columns), prediction_type='Probability')
202
+ return {"Prolonged LOS": float(pos_pred[0][1]), "Not Prolonged LOS": float(pos_pred[0][0])}
203
+
204
+ def y1_predict_rf(*args):
205
+ df = pd.DataFrame([args], columns=x_rf.columns)
206
+ df = df.astype({col: "category" for col in categorical_columns})
207
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
208
+ df = df.astype(d)
209
+ pos_pred = y1_model_rf.predict_proba(df)
210
+ return {"Prolonged LOS": float(pos_pred[0][1]), "Not Prolonged LOS": float(pos_pred[0][0])}
211
+
212
+
213
+ #Define predict for y2/DISCHARGE.
214
+
215
+ def y2_predict_xgb(*args):
216
+ df_xgb = pd.DataFrame([args], columns=x.columns)
217
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns})
218
+ pos_pred = y2_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
219
+ return {"Non-home Discharge": float(pos_pred[0]), "Home Discharge": 1 - float(pos_pred[0])}
220
+
221
+ def y2_predict_lgb(*args):
222
+ df = pd.DataFrame([args], columns=data.columns)
223
+ df = df.astype({col: "category" for col in categorical_columns})
224
+ pos_pred = y2_model_lgb.predict(df)
225
+ return {"Non-home Discharge": float(pos_pred[0]), "Home Discharge": 1 - float(pos_pred[0])}
226
+
227
+ def y2_predict_cb(*args):
228
+ df_cb = pd.DataFrame([args], columns=x.columns)
229
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns})
230
+ pos_pred = y2_model_cb.predict(Pool(df_cb, cat_features = categorical_columns), prediction_type='Probability')
231
+ return {"Non-home Discharge": float(pos_pred[0][1]), "Home Discharge": float(pos_pred[0][0])}
232
+
233
+ def y2_predict_rf(*args):
234
+ df = pd.DataFrame([args], columns=x_rf.columns)
235
+ df = df.astype({col: "category" for col in categorical_columns})
236
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
237
+ df = df.astype(d)
238
+ pos_pred = y2_model_rf.predict_proba(df)
239
+ return {"Non-home Discharge": float(pos_pred[0][1]), "Home Discharge": float(pos_pred[0][0])}
240
+
241
+
242
+ #Define predict for y3/READMISSION.
243
+
244
+ def y3_predict_xgb(*args):
245
+ df_xgb = pd.DataFrame([args], columns=x.columns)
246
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns})
247
+ pos_pred = y3_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
248
+ return {"No Readmission": float(pos_pred[0]), "Readmission": 1 - float(pos_pred[0])}
249
+
250
+ def y3_predict_lgb(*args):
251
+ df = pd.DataFrame([args], columns=data.columns)
252
+ df = df.astype({col: "category" for col in categorical_columns})
253
+ pos_pred = y3_model_lgb.predict(df)
254
+ return {"No Readmission": float(pos_pred[0]), "Readmission": 1 - float(pos_pred[0])}
255
+
256
+ def y3_predict_cb(*args):
257
+ df_cb = pd.DataFrame([args], columns=x.columns)
258
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns})
259
+ pos_pred = y3_model_cb.predict(Pool(df_cb, cat_features = categorical_columns), prediction_type='Probability')
260
+ return {"No Readmission": float(pos_pred[0][1]), "Readmission": float(pos_pred[0][0])}
261
+
262
+ def y3_predict_rf(*args):
263
+ df = pd.DataFrame([args], columns=x_rf.columns)
264
+ df = df.astype({col: "category" for col in categorical_columns})
265
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
266
+ df = df.astype(d)
267
+ pos_pred = y3_model_rf.predict_proba(df)
268
+
269
+
270
+ #Define interpret for y1/LOS.
271
+
272
+ def y1_interpret_xgb(*args):
273
+ df = pd.DataFrame([args], columns=x.columns)
274
+ df = df.astype({col: "category" for col in categorical_columns})
275
+ shap_values = y1_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
276
+ scores_desc = list(zip(shap_values[0], x.columns))
277
+ scores_desc = sorted(scores_desc)
278
+ fig_m = plt.figure(facecolor='white')
279
+ fig_m.set_size_inches(14, 10)
280
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
281
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
282
+ plt.yticks(fontsize=12)
283
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
284
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
285
+ return fig_m
286
+
287
+ def y1_interpret_lgb(*args):
288
+ df = pd.DataFrame([args], columns=x.columns)
289
+ df = df.astype({col: "category" for col in categorical_columns})
290
+ shap_values = y1_explainer_lgb.shap_values(df)
291
+ scores_desc = list(zip(shap_values[0][0], x.columns))
292
+ scores_desc = sorted(scores_desc)
293
+ fig_m = plt.figure(facecolor='white')
294
+ fig_m.set_size_inches(14, 10)
295
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
296
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
297
+ plt.yticks(fontsize=12)
298
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
299
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
300
+ return fig_m
301
+
302
+ def y1_interpret_cb(*args):
303
+ df = pd.DataFrame([args], columns=x.columns)
304
+ df = df.astype({col: "category" for col in categorical_columns})
305
+ shap_values = y1_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns))
306
+ scores_desc = list(zip(shap_values[0], x.columns))
307
+ scores_desc = sorted(scores_desc)
308
+ fig_m = plt.figure(facecolor='white')
309
+ fig_m.set_size_inches(14, 10)
310
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
311
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
312
+ plt.yticks(fontsize=12)
313
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
314
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
315
+ return fig_m
316
+
317
+ def y1_interpret_rf(*args):
318
+ df = pd.DataFrame([args], columns=x_rf.columns)
319
+ df = df.astype({col: "category" for col in categorical_columns})
320
+ shap_values = y1_explainer_rf.shap_values(df)
321
+ scores_desc = list(zip(shap_values[0][0], x_rf.columns))
322
+ scores_desc = sorted(scores_desc)
323
+ fig_m = plt.figure(facecolor='white')
324
+ fig_m.set_size_inches(14, 10)
325
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
326
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
327
+ plt.yticks(fontsize=12)
328
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
329
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
330
+ return fig_m
331
+
332
+
333
+ #Define interpret for y2/DISCHARGE.
334
+
335
+ def y2_interpret_xgb(*args):
336
+ df = pd.DataFrame([args], columns=x.columns)
337
+ df = df.astype({col: "category" for col in categorical_columns})
338
+ shap_values = y2_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
339
+ scores_desc = list(zip(shap_values[0], x.columns))
340
+ scores_desc = sorted(scores_desc)
341
+ fig_m = plt.figure(facecolor='white')
342
+ fig_m.set_size_inches(14, 10)
343
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
344
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
345
+ plt.yticks(fontsize=12)
346
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
347
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
348
+ return fig_m
349
+
350
+ def y2_interpret_lgb(*args):
351
+ df = pd.DataFrame([args], columns=x.columns)
352
+ df = df.astype({col: "category" for col in categorical_columns})
353
+ shap_values = y2_explainer_lgb.shap_values(df)
354
+ scores_desc = list(zip(shap_values[0][0], x.columns))
355
+ scores_desc = sorted(scores_desc)
356
+ fig_m = plt.figure(facecolor='white')
357
+ fig_m.set_size_inches(14, 10)
358
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
359
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
360
+ plt.yticks(fontsize=12)
361
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
362
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
363
+ return fig_m
364
+
365
+ def y2_interpret_cb(*args):
366
+ df = pd.DataFrame([args], columns=x.columns)
367
+ df = df.astype({col: "category" for col in categorical_columns})
368
+ shap_values = y2_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns))
369
+ scores_desc = list(zip(shap_values[0], x.columns))
370
+ scores_desc = sorted(scores_desc)
371
+ fig_m = plt.figure(facecolor='white')
372
+ fig_m.set_size_inches(14, 10)
373
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
374
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
375
+ plt.yticks(fontsize=12)
376
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
377
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
378
+ return fig_m
379
+
380
+ def y2_interpret_rf(*args):
381
+ df = pd.DataFrame([args], columns=x_rf.columns)
382
+ df = df.astype({col: "category" for col in categorical_columns})
383
+ shap_values = y2_explainer_rf.shap_values(df)
384
+ scores_desc = list(zip(shap_values[0][0], x_rf.columns))
385
+ scores_desc = sorted(scores_desc)
386
+ fig_m = plt.figure(facecolor='white')
387
+ fig_m.set_size_inches(14, 10)
388
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
389
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
390
+ plt.yticks(fontsize=12)
391
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
392
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
393
+ return fig_m
394
+
395
+
396
+ #Define interpret for y3/READMISSION.
397
+
398
+ def y3_interpret_xgb(*args):
399
+ df = pd.DataFrame([args], columns=x.columns)
400
+ df = df.astype({col: "category" for col in categorical_columns})
401
+ shap_values = y3_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
402
+ scores_desc = list(zip(shap_values[0], x.columns))
403
+ scores_desc = sorted(scores_desc)
404
+ fig_m = plt.figure(facecolor='white')
405
+ fig_m.set_size_inches(14, 10)
406
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
407
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
408
+ plt.yticks(fontsize=12)
409
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
410
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
411
+ return fig_m
412
+
413
+ def y3_interpret_lgb(*args):
414
+ df = pd.DataFrame([args], columns=x.columns)
415
+ df = df.astype({col: "category" for col in categorical_columns})
416
+ shap_values = y3_explainer_lgb.shap_values(df)
417
+ scores_desc = list(zip(shap_values[0][0], x.columns))
418
+ scores_desc = sorted(scores_desc)
419
+ fig_m = plt.figure(facecolor='white')
420
+ fig_m.set_size_inches(14, 10)
421
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
422
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
423
+ plt.yticks(fontsize=12)
424
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
425
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
426
+ return fig_m
427
+
428
+ def y3_interpret_cb(*args):
429
+ df = pd.DataFrame([args], columns=x.columns)
430
+ df = df.astype({col: "category" for col in categorical_columns})
431
+ shap_values = y3_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns))
432
+ scores_desc = list(zip(shap_values[0], x.columns))
433
+ scores_desc = sorted(scores_desc)
434
+ fig_m = plt.figure(facecolor='white')
435
+ fig_m.set_size_inches(14, 10)
436
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
437
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
438
+ plt.yticks(fontsize=12)
439
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
440
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
441
+ return fig_m
442
+
443
+ def y3_interpret_rf(*args):
444
+ df = pd.DataFrame([args], columns=x_rf.columns)
445
+ df = df.astype({col: "category" for col in categorical_columns})
446
+ shap_values = y3_explainer_rf.shap_values(df)
447
+ scores_desc = list(zip(shap_values[0][0], x_rf.columns))
448
+ scores_desc = sorted(scores_desc)
449
+ fig_m = plt.figure(facecolor='white')
450
+ fig_m.set_size_inches(14, 10)
451
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
452
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
453
+ plt.yticks(fontsize=12)
454
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
455
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
456
+ return fig_m
457
+
458
+ with gr.Blocks(title="NSQIP-PLF") as demo:
459
+
460
+ gr.Markdown(
461
+ """
462
+ """
463
+ )
464
+
465
+ gr.Markdown(
466
+ """
467
+ # Prediction Tool
468
+ ## Short-Term Postoperative Outcomes Following Posterior Lumbar Fusion
469
+ **The publication describing the details of this predictive tool will be posted here upon the acceptance of publication.**
470
+ ### Disclaimer
471
+
472
+ 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.
473
+
474
+ 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.
475
+
476
+ 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.
477
+
478
+ 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.
479
+
480
+ 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.
481
+
482
+ By using this tool, you accept all of the above terms.
483
+
484
+ """
485
+ )
486
+
487
+ with gr.Tab('Length of Stay'):
488
+
489
+ gr.Markdown(
490
+ """
491
+
492
+ ### Prolonged Length of Stay Prediction Model for Posterior Lumbar Fusion
493
+ """
494
+ )
495
+
496
+
497
+ with gr.Row():
498
+
499
+ with gr.Column():
500
+
501
+ AGE = gr.Slider(label="Age", minimum=17, maximum=99, step=1, randomize=True)
502
+
503
+ SEX = gr.Radio(
504
+ label="Sex",
505
+ choices=unique_sex,
506
+ type='index',
507
+ value=lambda: random.choice(unique_sex),
508
+ )
509
+
510
+ RACE = gr.Radio(
511
+ label="Race",
512
+ choices=unique_race,
513
+ type='index',
514
+ value=lambda: random.choice(unique_race),
515
+ )
516
+
517
+ HEIGHT = gr.Slider(label="Height (in meters)", minimum=1.0, maximum=2.25, step=0.01, randomize=True)
518
+
519
+ WEIGHT = gr.Slider(label="Weight (in kilograms)", minimum=20, maximum=200, step=1, randomize=True)
520
+
521
+ BMI = gr.Slider(label="BMI", minimum=10, maximum=70, step=1, randomize=True)
522
+
523
+ TRANST = gr.Radio(
524
+ label="Transfer Status",
525
+ choices=unique_transt,
526
+ type='index',
527
+ value=lambda: random.choice(unique_transt),
528
+ )
529
+
530
+ INOUT = gr.Radio(
531
+ label="Inpatient or Outpatient",
532
+ choices=unique_inout,
533
+ type='index',
534
+ value=lambda: random.choice(unique_inout),
535
+ )
536
+
537
+ SURGSPEC = gr.Radio(
538
+ label="Surgical Specialty",
539
+ choices=unique_surgspec,
540
+ type='index',
541
+ value=lambda: random.choice(unique_surgspec),
542
+ )
543
+
544
+ SMOKE = gr.Radio(
545
+ label="Smoking Status",
546
+ choices=unique_smoke,
547
+ type='index',
548
+ value=lambda: random.choice(unique_smoke),
549
+ )
550
+
551
+ DIABETES = gr.Radio(
552
+ label="Diabetes",
553
+ choices=unique_diabetes,
554
+ type='index',
555
+ value=lambda: random.choice(unique_diabetes),
556
+ )
557
+
558
+ DYSPNEA = gr.Radio(
559
+ label="Dyspnea",
560
+ choices=unique_dyspnea,
561
+ type='index',
562
+ value=lambda: random.choice(unique_dyspnea),
563
+ )
564
+
565
+ VENTILAT = gr.Radio(
566
+ label="Ventilator Dependency",
567
+ choices=unique_ventilat,
568
+ type='index',
569
+ value=lambda: random.choice(unique_ventilat),
570
+ )
571
+
572
+ HXCOPD = gr.Radio(
573
+ label="History of COPD",
574
+ choices=unique_hxcopd,
575
+ type='index',
576
+ value=lambda: random.choice(unique_hxcopd),
577
+ )
578
+
579
+ ASCITES = gr.Radio(
580
+ label="Ascites",
581
+ choices=unique_ascites,
582
+ type='index',
583
+ value=lambda: random.choice(unique_ascites),
584
+ )
585
+
586
+ HXCHF = gr.Radio(
587
+ label="History of Congestive Heart Failure",
588
+ choices=unique_hxchf,
589
+ type='index',
590
+ value=lambda: random.choice(unique_hxchf),
591
+ )
592
+
593
+ HYPERMED = gr.Radio(
594
+ label="Hypertension Despite Medication",
595
+ choices=unique_hypermed,
596
+ type='index',
597
+ value=lambda: random.choice(unique_hypermed),
598
+ )
599
+
600
+ RENAFAIL = gr.Radio(
601
+ label="Renal Failure",
602
+ choices=unique_renafail,
603
+ type='index',
604
+ value=lambda: random.choice(unique_renafail),
605
+ )
606
+
607
+ DIALYSIS = gr.Radio(
608
+ label="Dialysis",
609
+ choices=unique_dialysis,
610
+ type='index',
611
+ value=lambda: random.choice(unique_dialysis),
612
+ )
613
+
614
+ STEROID = gr.Radio(
615
+ label="Steroid",
616
+ choices=unique_steroid,
617
+ type='index',
618
+ value=lambda: random.choice(unique_steroid),
619
+ )
620
+
621
+ WTLOSS = gr.Radio(
622
+ label="Weight Loss",
623
+ choices=unique_wtloss,
624
+ type='index',
625
+ value=lambda: random.choice(unique_wtloss),
626
+ )
627
+
628
+ BLEEDDIS = gr.Radio(
629
+ label="Bleeding Disorder",
630
+ choices=unique_bleeddis,
631
+ type='index',
632
+ value=lambda: random.choice(unique_bleeddis),
633
+ )
634
+
635
+ TRANSFUS = gr.Radio(
636
+ label="Transfusion",
637
+ choices=unique_transfus,
638
+ type='index',
639
+ value=lambda: random.choice(unique_transfus),
640
+ )
641
+
642
+ WNDINF = gr.Radio(
643
+ label="Wound Infection",
644
+ choices=unique_wndinf,
645
+ type='index',
646
+ value=lambda: random.choice(unique_wndinf),
647
+ )
648
+
649
+ DISCANCR = gr.Radio(
650
+ label="Disseminated Cancer",
651
+ choices=unique_discancr,
652
+ type='index',
653
+ value=lambda: random.choice(unique_discancr),
654
+ )
655
+
656
+ FNSTATUS2 = gr.Radio(
657
+ label="Functional Status",
658
+ choices=unique_fnstatus2,
659
+ type='index',
660
+ value=lambda: random.choice(unique_fnstatus2),
661
+ )
662
+
663
+ PRSODM = gr.Slider(label="Sodium", minimum=min(x['PRSODM']), maximum=max(x['PRSODM']), step=1, randomize=True)
664
+
665
+ PRBUN = gr.Slider(label="BUN", minimum=min(x['PRBUN']), maximum=max(x['PRBUN']), step=1, randomize=True)
666
+
667
+ PRCREAT = gr.Slider(label="Creatine", minimum=min(x['PRCREAT']),maximum=max(x['PRCREAT']), step=0.1, randomize=True)
668
+
669
+ PRWBC = gr.Slider(label="WBC", minimum=min(x['PRWBC']), maximum=max(x['PRWBC']), step=0.1, randomize=True)
670
+
671
+ PRHCT = gr.Slider(label="Hematocrit", minimum=min(x['PRHCT']), maximum=max(x['PRHCT']), step=0.1, randomize=True)
672
+
673
+ PRPLATE = gr.Slider(label="Platelet", minimum=min(x['PRPLATE']), maximum=max(x['PRPLATE']), step=1, randomize=True)
674
+
675
+ ASACLAS = gr.Radio(
676
+ label="ASA Class",
677
+ choices=unique_asaclas,
678
+ type='index',
679
+ value=lambda: random.choice(unique_asaclas),
680
+
681
+ )
682
+
683
+ LEVELS = gr.Radio(
684
+ label="Levels",
685
+ choices=unique_levels,
686
+ type='index',
687
+ value=lambda: random.choice(unique_levels),
688
+ )
689
+
690
+ with gr.Column():
691
+
692
+ with gr.Row():
693
+ y1_predict_btn_xgb = gr.Button(value="Predict (XGBoost)")
694
+ y1_predict_btn_lgb = gr.Button(value="Predict (LightGBM)")
695
+ y1_predict_btn_cb = gr.Button(value="Predict (CatBoost)")
696
+ y1_predict_btn_rf = gr.Button(value="Predict (Random Forest)")
697
+ label = gr.Label()
698
+
699
+ with gr.Row():
700
+ y1_interpret_btn_xgb = gr.Button(value="Explain (XGBoost)")
701
+ y1_interpret_btn_lgb = gr.Button(value="Explain (LightGBM)")
702
+ y1_interpret_btn_cb = gr.Button(value="Explain (CatBoost)")
703
+ y1_interpret_btn_rf = gr.Button(value="Explain (Random Forest)")
704
+
705
+ plot = gr.Plot()
706
+
707
+ y1_predict_btn_xgb.click(
708
+ y1_predict_xgb,
709
+ inputs=[SEX, INOUT, 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,],
710
+ outputs=[label]
711
+ )
712
+
713
+ y1_predict_btn_lgb.click(
714
+ y1_predict_lgb,
715
+ inputs=[SEX, INOUT, 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,],
716
+ outputs=[label]
717
+ )
718
+
719
+ y1_predict_btn_cb.click(
720
+ y1_predict_cb,
721
+ inputs=[SEX, INOUT, 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,],
722
+ outputs=[label]
723
+ )
724
+
725
+ y1_predict_btn_rf.click(
726
+ y1_predict_rf,
727
+ inputs=[SEX, INOUT, 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,],
728
+ outputs=[label]
729
+ )
730
+
731
+ y1_interpret_btn_xgb.click(
732
+ y1_interpret_xgb,
733
+ inputs=[SEX, INOUT, 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,],
734
+ outputs=[plot],
735
+ )
736
+
737
+ y1_interpret_btn_lgb.click(
738
+ y1_interpret_lgb,
739
+ inputs=[SEX, INOUT, 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,],
740
+ outputs=[plot],
741
+ )
742
+
743
+ y1_interpret_btn_cb.click(
744
+ y1_interpret_cb,
745
+ inputs=[SEX, INOUT, 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,],
746
+ outputs=[plot],
747
+ )
748
+
749
+ y1_interpret_btn_rf.click(
750
+ y1_interpret_rf,
751
+ inputs=[SEX, INOUT, 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,],
752
+ outputs=[plot],
753
+ )
754
+
755
+ with gr.Tab('Non-home Discharge'):
756
+
757
+ gr.Markdown(
758
+ """
759
+
760
+ ### Non-home Discharge Prediction Model for Posterior Lumbar Fusion
761
+ """
762
+ )
763
+
764
+
765
+ with gr.Row():
766
+
767
+ with gr.Column():
768
+
769
+ AGE = gr.Slider(label="Age", minimum=17, maximum=99, step=1, randomize=True)
770
+
771
+ SEX = gr.Radio(
772
+ label="Sex",
773
+ choices=unique_sex,
774
+ type='index',
775
+ value=lambda: random.choice(unique_sex),
776
+ )
777
+
778
+ RACE = gr.Radio(
779
+ label="Race",
780
+ choices=unique_race,
781
+ type='index',
782
+ value=lambda: random.choice(unique_race),
783
+ )
784
+
785
+ HEIGHT = gr.Slider(label="Height (in meters)", minimum=1.0, maximum=2.25, step=0.01, randomize=True)
786
+
787
+ WEIGHT = gr.Slider(label="Weight (in kilograms)", minimum=20, maximum=200, step=1, randomize=True)
788
+
789
+ BMI = gr.Slider(label="BMI", minimum=10, maximum=70, step=1, randomize=True)
790
+
791
+ TRANST = gr.Radio(
792
+ label="Transfer Status",
793
+ choices=unique_transt,
794
+ type='index',
795
+ value=lambda: random.choice(unique_transt),
796
+ )
797
+
798
+ INOUT = gr.Radio(
799
+ label="Inpatient or Outpatient",
800
+ choices=unique_inout,
801
+ type='index',
802
+ value=lambda: random.choice(unique_inout),
803
+ )
804
+
805
+ SURGSPEC = gr.Radio(
806
+ label="Surgical Specialty",
807
+ choices=unique_surgspec,
808
+ type='index',
809
+ value=lambda: random.choice(unique_surgspec),
810
+ )
811
+
812
+ SMOKE = gr.Radio(
813
+ label="Smoking Status",
814
+ choices=unique_smoke,
815
+ type='index',
816
+ value=lambda: random.choice(unique_smoke),
817
+ )
818
+
819
+ DIABETES = gr.Radio(
820
+ label="Diabetes",
821
+ choices=unique_diabetes,
822
+ type='index',
823
+ value=lambda: random.choice(unique_diabetes),
824
+ )
825
+
826
+ DYSPNEA = gr.Radio(
827
+ label="Dyspnea",
828
+ choices=unique_dyspnea,
829
+ type='index',
830
+ value=lambda: random.choice(unique_dyspnea),
831
+ )
832
+
833
+ VENTILAT = gr.Radio(
834
+ label="Ventilator Dependency",
835
+ choices=unique_ventilat,
836
+ type='index',
837
+ value=lambda: random.choice(unique_ventilat),
838
+ )
839
+
840
+ HXCOPD = gr.Radio(
841
+ label="History of COPD",
842
+ choices=unique_hxcopd,
843
+ type='index',
844
+ value=lambda: random.choice(unique_hxcopd),
845
+ )
846
+
847
+ ASCITES = gr.Radio(
848
+ label="Ascites",
849
+ choices=unique_ascites,
850
+ type='index',
851
+ value=lambda: random.choice(unique_ascites),
852
+ )
853
+
854
+ HXCHF = gr.Radio(
855
+ label="History of Congestive Heart Failure",
856
+ choices=unique_hxchf,
857
+ type='index',
858
+ value=lambda: random.choice(unique_hxchf),
859
+ )
860
+
861
+ HYPERMED = gr.Radio(
862
+ label="Hypertension Despite Medication",
863
+ choices=unique_hypermed,
864
+ type='index',
865
+ value=lambda: random.choice(unique_hypermed),
866
+ )
867
+
868
+ RENAFAIL = gr.Radio(
869
+ label="Renal Failure",
870
+ choices=unique_renafail,
871
+ type='index',
872
+ value=lambda: random.choice(unique_renafail),
873
+ )
874
+
875
+ DIALYSIS = gr.Radio(
876
+ label="Dialysis",
877
+ choices=unique_dialysis,
878
+ type='index',
879
+ value=lambda: random.choice(unique_dialysis),
880
+ )
881
+
882
+ STEROID = gr.Radio(
883
+ label="Steroid",
884
+ choices=unique_steroid,
885
+ type='index',
886
+ value=lambda: random.choice(unique_steroid),
887
+ )
888
+
889
+ WTLOSS = gr.Radio(
890
+ label="Weight Loss",
891
+ choices=unique_wtloss,
892
+ type='index',
893
+ value=lambda: random.choice(unique_wtloss),
894
+ )
895
+
896
+ BLEEDDIS = gr.Radio(
897
+ label="Bleeding Disorder",
898
+ choices=unique_bleeddis,
899
+ type='index',
900
+ value=lambda: random.choice(unique_bleeddis),
901
+ )
902
+
903
+ TRANSFUS = gr.Radio(
904
+ label="Transfusion",
905
+ choices=unique_transfus,
906
+ type='index',
907
+ value=lambda: random.choice(unique_transfus),
908
+ )
909
+
910
+ WNDINF = gr.Radio(
911
+ label="Wound Infection",
912
+ choices=unique_wndinf,
913
+ type='index',
914
+ value=lambda: random.choice(unique_wndinf),
915
+ )
916
+
917
+ DISCANCR = gr.Radio(
918
+ label="Disseminated Cancer",
919
+ choices=unique_discancr,
920
+ type='index',
921
+ value=lambda: random.choice(unique_discancr),
922
+ )
923
+
924
+ FNSTATUS2 = gr.Radio(
925
+ label="Functional Status",
926
+ choices=unique_fnstatus2,
927
+ type='index',
928
+ value=lambda: random.choice(unique_fnstatus2),
929
+ )
930
+
931
+ PRSODM = gr.Slider(label="Sodium", minimum=min(x['PRSODM']), maximum=max(x['PRSODM']), step=1, randomize=True)
932
+
933
+ PRBUN = gr.Slider(label="BUN", minimum=min(x['PRBUN']), maximum=max(x['PRBUN']), step=1, randomize=True)
934
+
935
+ PRCREAT = gr.Slider(label="Creatine", minimum=min(x['PRCREAT']),maximum=max(x['PRCREAT']), step=0.1, randomize=True)
936
+
937
+ PRWBC = gr.Slider(label="WBC", minimum=min(x['PRWBC']), maximum=max(x['PRWBC']), step=0.1, randomize=True)
938
+
939
+ PRHCT = gr.Slider(label="Hematocrit", minimum=min(x['PRHCT']), maximum=max(x['PRHCT']), step=0.1, randomize=True)
940
+
941
+ PRPLATE = gr.Slider(label="Platelet", minimum=min(x['PRPLATE']), maximum=max(x['PRPLATE']), step=1, randomize=True)
942
+
943
+ ASACLAS = gr.Radio(
944
+ label="ASA Class",
945
+ choices=unique_asaclas,
946
+ type='index',
947
+ value=lambda: random.choice(unique_asaclas),
948
+
949
+ )
950
+
951
+ LEVELS = gr.Radio(
952
+ label="Levels",
953
+ choices=unique_levels,
954
+ type='index',
955
+ value=lambda: random.choice(unique_levels),
956
+ )
957
+
958
+ with gr.Column():
959
+
960
+ with gr.Row():
961
+ y2_predict_btn_xgb = gr.Button(value="Predict (XGBoost)")
962
+ y2_predict_btn_lgb = gr.Button(value="Predict (LightGBM)")
963
+ y2_predict_btn_cb = gr.Button(value="Predict (CatBoost)")
964
+ y2_predict_btn_rf = gr.Button(value="Predict (Random Forest)")
965
+ label = gr.Label()
966
+
967
+ with gr.Row():
968
+ y2_interpret_btn_xgb = gr.Button(value="Explain (XGBoost)")
969
+ y2_interpret_btn_lgb = gr.Button(value="Explain (LightGBM)")
970
+ y2_interpret_btn_cb = gr.Button(value="Explain (CatBoost)")
971
+ y2_interpret_btn_rf = gr.Button(value="Explain (Random Forest)")
972
+
973
+ plot = gr.Plot()
974
+
975
+ y2_predict_btn_xgb.click(
976
+ y2_predict_xgb,
977
+ inputs=[SEX, INOUT, 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,],
978
+ outputs=[label]
979
+ )
980
+
981
+ y2_predict_btn_lgb.click(
982
+ y2_predict_lgb,
983
+ inputs=[SEX, INOUT, 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,],
984
+ outputs=[label]
985
+ )
986
+
987
+ y2_predict_btn_cb.click(
988
+ y2_predict_cb,
989
+ inputs=[SEX, INOUT, 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,],
990
+ outputs=[label]
991
+ )
992
+
993
+ y2_predict_btn_rf.click(
994
+ y2_predict_rf,
995
+ inputs=[SEX, INOUT, 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,],
996
+ outputs=[label]
997
+ )
998
+
999
+ y2_interpret_btn_xgb.click(
1000
+ y2_interpret_xgb,
1001
+ inputs=[SEX, INOUT, 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,],
1002
+ outputs=[plot],
1003
+ )
1004
+
1005
+ y2_interpret_btn_lgb.click(
1006
+ y2_interpret_lgb,
1007
+ inputs=[SEX, INOUT, 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,],
1008
+ outputs=[plot],
1009
+ )
1010
+
1011
+ y2_interpret_btn_cb.click(
1012
+ y2_interpret_cb,
1013
+ inputs=[SEX, INOUT, 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,],
1014
+ outputs=[plot],
1015
+ )
1016
+
1017
+ y2_interpret_btn_rf.click(
1018
+ y2_interpret_rf,
1019
+ inputs=[SEX, INOUT, 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,],
1020
+ outputs=[plot],
1021
+ )
1022
+
1023
+ with gr.Tab('Readmission'):
1024
+
1025
+ gr.Markdown(
1026
+ """
1027
+
1028
+ ### Readmission Prediction Model for Posterior Lumbar Fusion
1029
+ """
1030
+ )
1031
+
1032
+
1033
+ with gr.Row():
1034
+
1035
+ with gr.Column():
1036
+
1037
+ AGE = gr.Slider(label="Age", minimum=17, maximum=99, step=1, randomize=True)
1038
+
1039
+ SEX = gr.Radio(
1040
+ label="Sex",
1041
+ choices=unique_sex,
1042
+ type='index',
1043
+ value=lambda: random.choice(unique_sex),
1044
+ )
1045
+
1046
+ RACE = gr.Radio(
1047
+ label="Race",
1048
+ choices=unique_race,
1049
+ type='index',
1050
+ value=lambda: random.choice(unique_race),
1051
+ )
1052
+
1053
+ HEIGHT = gr.Slider(label="Height (in meters)", minimum=1.0, maximum=2.25, step=0.01, randomize=True)
1054
+
1055
+ WEIGHT = gr.Slider(label="Weight (in kilograms)", minimum=20, maximum=200, step=1, randomize=True)
1056
+
1057
+ BMI = gr.Slider(label="BMI", minimum=10, maximum=70, step=1, randomize=True)
1058
+
1059
+ TRANST = gr.Radio(
1060
+ label="Transfer Status",
1061
+ choices=unique_transt,
1062
+ type='index',
1063
+ value=lambda: random.choice(unique_transt),
1064
+ )
1065
+
1066
+ INOUT = gr.Radio(
1067
+ label="Inpatient or Outpatient",
1068
+ choices=unique_inout,
1069
+ type='index',
1070
+ value=lambda: random.choice(unique_inout),
1071
+ )
1072
+
1073
+ SURGSPEC = gr.Radio(
1074
+ label="Surgical Specialty",
1075
+ choices=unique_surgspec,
1076
+ type='index',
1077
+ value=lambda: random.choice(unique_surgspec),
1078
+ )
1079
+
1080
+ SMOKE = gr.Radio(
1081
+ label="Smoking Status",
1082
+ choices=unique_smoke,
1083
+ type='index',
1084
+ value=lambda: random.choice(unique_smoke),
1085
+ )
1086
+
1087
+ DIABETES = gr.Radio(
1088
+ label="Diabetes",
1089
+ choices=unique_diabetes,
1090
+ type='index',
1091
+ value=lambda: random.choice(unique_diabetes),
1092
+ )
1093
+
1094
+ DYSPNEA = gr.Radio(
1095
+ label="Dyspnea",
1096
+ choices=unique_dyspnea,
1097
+ type='index',
1098
+ value=lambda: random.choice(unique_dyspnea),
1099
+ )
1100
+
1101
+ VENTILAT = gr.Radio(
1102
+ label="Ventilator Dependency",
1103
+ choices=unique_ventilat,
1104
+ type='index',
1105
+ value=lambda: random.choice(unique_ventilat),
1106
+ )
1107
+
1108
+ HXCOPD = gr.Radio(
1109
+ label="History of COPD",
1110
+ choices=unique_hxcopd,
1111
+ type='index',
1112
+ value=lambda: random.choice(unique_hxcopd),
1113
+ )
1114
+
1115
+ ASCITES = gr.Radio(
1116
+ label="Ascites",
1117
+ choices=unique_ascites,
1118
+ type='index',
1119
+ value=lambda: random.choice(unique_ascites),
1120
+ )
1121
+
1122
+ HXCHF = gr.Radio(
1123
+ label="History of Congestive Heart Failure",
1124
+ choices=unique_hxchf,
1125
+ type='index',
1126
+ value=lambda: random.choice(unique_hxchf),
1127
+ )
1128
+
1129
+ HYPERMED = gr.Radio(
1130
+ label="Hypertension Despite Medication",
1131
+ choices=unique_hypermed,
1132
+ type='index',
1133
+ value=lambda: random.choice(unique_hypermed),
1134
+ )
1135
+
1136
+ RENAFAIL = gr.Radio(
1137
+ label="Renal Failure",
1138
+ choices=unique_renafail,
1139
+ type='index',
1140
+ value=lambda: random.choice(unique_renafail),
1141
+ )
1142
+
1143
+ DIALYSIS = gr.Radio(
1144
+ label="Dialysis",
1145
+ choices=unique_dialysis,
1146
+ type='index',
1147
+ value=lambda: random.choice(unique_dialysis),
1148
+ )
1149
+
1150
+ STEROID = gr.Radio(
1151
+ label="Steroid",
1152
+ choices=unique_steroid,
1153
+ type='index',
1154
+ value=lambda: random.choice(unique_steroid),
1155
+ )
1156
+
1157
+ WTLOSS = gr.Radio(
1158
+ label="Weight Loss",
1159
+ choices=unique_wtloss,
1160
+ type='index',
1161
+ value=lambda: random.choice(unique_wtloss),
1162
+ )
1163
+
1164
+ BLEEDDIS = gr.Radio(
1165
+ label="Bleeding Disorder",
1166
+ choices=unique_bleeddis,
1167
+ type='index',
1168
+ value=lambda: random.choice(unique_bleeddis),
1169
+ )
1170
+
1171
+ TRANSFUS = gr.Radio(
1172
+ label="Transfusion",
1173
+ choices=unique_transfus,
1174
+ type='index',
1175
+ value=lambda: random.choice(unique_transfus),
1176
+ )
1177
+
1178
+ WNDINF = gr.Radio(
1179
+ label="Wound Infection",
1180
+ choices=unique_wndinf,
1181
+ type='index',
1182
+ value=lambda: random.choice(unique_wndinf),
1183
+ )
1184
+
1185
+ DISCANCR = gr.Radio(
1186
+ label="Disseminated Cancer",
1187
+ choices=unique_discancr,
1188
+ type='index',
1189
+ value=lambda: random.choice(unique_discancr),
1190
+ )
1191
+
1192
+ FNSTATUS2 = gr.Radio(
1193
+ label="Functional Status",
1194
+ choices=unique_fnstatus2,
1195
+ type='index',
1196
+ value=lambda: random.choice(unique_fnstatus2),
1197
+ )
1198
+
1199
+ PRSODM = gr.Slider(label="Sodium", minimum=min(x['PRSODM']), maximum=max(x['PRSODM']), step=1, randomize=True)
1200
+
1201
+ PRBUN = gr.Slider(label="BUN", minimum=min(x['PRBUN']), maximum=max(x['PRBUN']), step=1, randomize=True)
1202
+
1203
+ PRCREAT = gr.Slider(label="Creatine", minimum=min(x['PRCREAT']),maximum=max(x['PRCREAT']), step=0.1, randomize=True)
1204
+
1205
+ PRWBC = gr.Slider(label="WBC", minimum=min(x['PRWBC']), maximum=max(x['PRWBC']), step=0.1, randomize=True)
1206
+
1207
+ PRHCT = gr.Slider(label="Hematocrit", minimum=min(x['PRHCT']), maximum=max(x['PRHCT']), step=0.1, randomize=True)
1208
+
1209
+ PRPLATE = gr.Slider(label="Platelet", minimum=min(x['PRPLATE']), maximum=max(x['PRPLATE']), step=1, randomize=True)
1210
+
1211
+ ASACLAS = gr.Radio(
1212
+ label="ASA Class",
1213
+ choices=unique_asaclas,
1214
+ type='index',
1215
+ value=lambda: random.choice(unique_asaclas),
1216
+
1217
+ )
1218
+
1219
+ LEVELS = gr.Radio(
1220
+ label="Levels",
1221
+ choices=unique_levels,
1222
+ type='index',
1223
+ value=lambda: random.choice(unique_levels),
1224
+ )
1225
+
1226
+ with gr.Column():
1227
+
1228
+ with gr.Row():
1229
+ y3_predict_btn_xgb = gr.Button(value="Predict (XGBoost)")
1230
+ y3_predict_btn_lgb = gr.Button(value="Predict (LightGBM)")
1231
+ y3_predict_btn_cb = gr.Button(value="Predict (CatBoost)")
1232
+ y3_predict_btn_rf = gr.Button(value="Predict (Random Forest)")
1233
+ label = gr.Label()
1234
+
1235
+ with gr.Row():
1236
+ y3_interpret_btn_xgb = gr.Button(value="Explain (XGBoost)")
1237
+ y3_interpret_btn_lgb = gr.Button(value="Explain (LightGBM)")
1238
+ y3_interpret_btn_cb = gr.Button(value="Explain (CatBoost)")
1239
+ y3_interpret_btn_rf = gr.Button(value="Explain (Random Forest)")
1240
+
1241
+ plot = gr.Plot()
1242
+
1243
+ y3_predict_btn_xgb.click(
1244
+ y3_predict_xgb,
1245
+ inputs=[SEX, INOUT, 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,],
1246
+ outputs=[label]
1247
+ )
1248
+
1249
+ y3_predict_btn_lgb.click(
1250
+ y3_predict_lgb,
1251
+ inputs=[SEX, INOUT, 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,],
1252
+ outputs=[label]
1253
+ )
1254
+
1255
+ y3_predict_btn_cb.click(
1256
+ y3_predict_cb,
1257
+ inputs=[SEX, INOUT, 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,],
1258
+ outputs=[label]
1259
+ )
1260
+
1261
+ y3_predict_btn_rf.click(
1262
+ y3_predict_rf,
1263
+ inputs=[SEX, INOUT, 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,],
1264
+ outputs=[label]
1265
+ )
1266
+
1267
+ y3_interpret_btn_xgb.click(
1268
+ y3_interpret_xgb,
1269
+ inputs=[SEX, INOUT, 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,],
1270
+ outputs=[plot],
1271
+ )
1272
+
1273
+ y3_interpret_btn_lgb.click(
1274
+ y3_interpret_lgb,
1275
+ inputs=[SEX, INOUT, 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,],
1276
+ outputs=[plot],
1277
+ )
1278
+
1279
+ y3_interpret_btn_cb.click(
1280
+ y3_interpret_cb,
1281
+ inputs=[SEX, INOUT, 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,],
1282
+ outputs=[plot],
1283
+ )
1284
+
1285
+ y3_interpret_btn_rf.click(
1286
+ y3_interpret_rf,
1287
+ inputs=[SEX, INOUT, 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,],
1288
+ outputs=[plot],
1289
+ )
1290
+
1291
+ 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