mertkarabacak commited on
Commit
49e436b
1 Parent(s): 893874e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +998 -0
app.py ADDED
@@ -0,0 +1,998 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
9
+ from sklearn.model_selection import train_test_split
10
+ from sklearn.calibration import calibration_curve
11
+ from math import sqrt
12
+ from scipy import stats as st
13
+ from random import randrange
14
+ from matplotlib import pyplot
15
+ import xgboost as xgb
16
+ import lightgbm as lgb
17
+ import catboost as cb
18
+ from sklearn.ensemble import RandomForestClassifier
19
+ import optuna
20
+ from optuna.samplers import TPESampler
21
+ import shap
22
+ import gradio as gr
23
+ import random
24
+
25
+ #Read data.
26
+ from datasets import load_dataset
27
+ x1 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="mortality_data.csv", use_auth_token = HF_TOKEN)
28
+ x1 = pd.DataFrame(x1['train'])
29
+
30
+ x2 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="discharge_data.csv", use_auth_token = HF_TOKEN)
31
+ x2 = pd.DataFrame(x2['train'])
32
+
33
+ x3 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="los_data.csv", use_auth_token = HF_TOKEN)
34
+ x3 = pd.DataFrame(x3['train'])
35
+
36
+ x4 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="iculos_data.csv", use_auth_token = HF_TOKEN)
37
+ x4 = pd.DataFrame(x4['train'])
38
+
39
+ x5 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="complications_data.csv", use_auth_token = HF_TOKEN)
40
+ x5 = pd.DataFrame(x5['train'])
41
+
42
+ #Define inputs.
43
+ inputs = ['Age', 'Sex', 'Race', 'Ethnicity', 'Weight', 'Height', 'Systolic_Blood_Pressure', 'Pulse_Rate', 'Supplemental_Oxygen', 'Pulse_Oximetry', 'Respiratory_Assistance', 'Respiratory_Rate', 'Temperature', 'PreHospital_Cardiac_Arrest', 'GCS__Eye', 'GCS__Verbal', 'GCS__Motor', 'Pupillary_Response', 'Midline_Shift', 'Current_Smoker', 'Comorbid_Condition__Alcohol_Use_Disorder', 'Comorbid_Condition__Substance_Abuse_Disorder', 'Comorbid_Condition__Diabetes_Mellitus', 'Comorbid_Condition__Hypertension', 'Comorbid_Condition__Congestive_Heart_Failure', 'History_of_Myocardial_Infarction', 'Comorbid_Condition__Angina_Pectoris', 'History_of_Cerebrovascular_Accident', 'Comorbid_Condition__Peripheral_Arterial_Disease', 'Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease', 'Comorbid_Condition__Chronic_Renal_Failure', 'Comorbid_Condition__Cirrhosis', 'Comorbid_Condition__Bleeding_Disorder', 'Comorbid_Condition__Disseminated_Cancer', 'Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer', 'Comorbid_Condition__Dementia', 'Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder', 'Comorbid_Condition__Mental_or_Personality_Disorder', 'Ability_to_Complete_AgeAppropriate_ADL', 'Pregnancy', 'Anticoagulant_Therapy', 'Steroid_Use', 'Advanced_Directive_Limiting_Care', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', 'Protective_Device', 'WorkRelated', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Head', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Face', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Neck', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Thorax', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Abdomen', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Spine', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Upper_Extremity', 'AIS_Severity__Maximum_Severity_of_Injury_in_the_Lower_Extremity', 'AIS_Severity__Maximum_Severity_of_Injury_in_Unspecified_Body_Regions', 'AIS_derived_ISS', 'Blood_Transfusion', 'Neurosurgical_Intervention', 'Cerebral_Monitoring', 'Alcohol_Screen', 'Alcohol_Screen_Result', 'Drug_Screen__Amphetamine', 'Drug_Screen__Barbiturate', 'Drug_Screen__Benzodiazepines', 'Drug_Screen__Cannabinoid', 'Drug_Screen__Cocaine', 'Drug_Screen__MDMA_or_Ecstasy', 'Drug_Screen__Methadone', 'Drug_Screen__Methamphetamine', 'Drug_Screen__Not_Tested', 'Drug_Screen__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment',]
44
+
45
+ #Assign unique values as answer options.
46
+ unique_SEX = ['Male', 'Female', 'Unknown']
47
+ unique_RACE = ['White', 'Black', 'Asian', 'American Indian', 'Pacific Islander', 'Other', 'Unknown']
48
+ unique_ETHNICITY = ['Not Hispanic or Latino', 'Hispanic or Latino', 'Unknown']
49
+ unique_SUPPLEMENTALOXYGEN = ['No supplemental oxygen', 'Supplemental oxygen', 'Unknown']
50
+ unique_RESPIRATORYASSISTANCE = ['Unassisted respiratory rate', 'Assisted respiratory rate', 'Unknown']
51
+ unique_PREHOSPITALCARDIACARREST = ['No', 'Yes', 'Unknown']
52
+ unique_TBIMIDLINESHIFT = ['No', 'Yes', 'Not imaged/unknown']
53
+ unique_TBIPUPILLARYRESPONSE = ['Both reactive', 'One reactive', 'Neither reactive', 'Unknown']
54
+ unique_CC_ADHD = ['No', 'Yes', 'Unknown']
55
+ unique_CC_ADLC = ['No', 'Yes', 'Unknown']
56
+ unique_CC_ALCOHOLISM = ['No', 'Yes', 'Unknown']
57
+ unique_CC_ANGINAPECTORIS = ['No', 'Yes', 'Unknown']
58
+ unique_CC_ANTICOAGULANT = ['No', 'Yes', 'Unknown']
59
+ unique_CC_BLEEDING = ['No', 'Yes', 'Unknown']
60
+ unique_CC_CHEMO = ['No', 'Yes', 'Unknown']
61
+ unique_CC_CHF = ['No', 'Yes', 'Unknown']
62
+ unique_CC_CIRRHOSIS = ['No', 'Yes', 'Unknown']
63
+ unique_CC_COPD = ['No', 'Yes', 'Unknown']
64
+ unique_CC_CVA = ['No', 'Yes', 'Unknown']
65
+ unique_CC_DEMENTIA = ['No', 'Yes', 'Unknown']
66
+ unique_CC_DIABETES = ['No', 'Yes', 'Unknown']
67
+ unique_CC_DISCANCER = ['No', 'Yes', 'Unknown']
68
+ unique_CC_FUNCTIONAL = ['No', 'Yes', 'Unknown']
69
+ unique_CC_HYPERTENSION = ['No', 'Yes', 'Unknown']
70
+ unique_CC_MENTALPERSONALITY = ['No', 'Yes', 'Unknown']
71
+ unique_CC_MI = ['No', 'Yes', 'Unknown']
72
+ unique_CC_PAD = ['No', 'Yes', 'Unknown']
73
+ unique_CC_RENAL = ['No', 'Yes', 'Unknown']
74
+ unique_CC_SMOKING = ['No', 'Yes', 'Unknown']
75
+ unique_CC_STEROID = ['No', 'Yes', 'Unknown']
76
+ unique_CC_SUBSTANCEABUSE = ['No', 'Yes', 'Unknown']
77
+ unique_CC_PREGNANCY = ['No', 'Yes', 'Unknown', 'Not applicable (male patient)']
78
+ unique_TRANSPORTMODE = ['Ground ambulance', 'Private vehicle/public vehicle/walk-in', 'Air ambulance', 'Police', 'Other/unknown']
79
+ unique_INTERFACILITYTRANSFER = ['No', 'Yes']
80
+ unique_TRAUMATYPE = ['Blunt', 'Penetrating', 'Other/unknown']
81
+ unique_INTENT = ['Unintentional', 'Assault', 'Self-inflicted', 'Other/undetermined/unknown']
82
+ unique_MECHANISM = ['Fall', 'Struck by or against', 'MVT occupant', 'MVT pedestrian', 'MVT motorcyclist', 'MVT pedal cyclist', 'Other MVT', 'Other transport', 'Other pedestrian', 'Other pedal cyclist', 'Firearm', 'Cut/pierce', 'Natural/environmental', 'Machinery', 'Overexertion', 'Other/unspecified/unknown']
83
+ unique_PROTDEV = ['None', 'Airbag present', 'Helmet', 'Lap belt', 'Shoulder Belt', 'Protective clothing', 'Protective non-clothing gear', 'Eye protection', 'Unknown']
84
+ unique_WORKRELATED = ['No', 'Yes (Unknown)', 'Yes (Construction and Extraction Occupations)', 'Yes (Transportation and Material Moving Occupations)', 'Yes (Installation, Maintenance, and Repair Occupations)', 'Yes (Farming, Fishing, and Forestry Occupations)', 'Yes (Building and Grounds Cleaning and Maintenance)', 'Yes (Food Preparation and Serving Related)', 'Yes (Production Occupations)', 'Yes (Sales and Related Occupations)', 'Yes (Arts, Design, Entertainment, Sports, and Media)', 'Yes (Military Specific Occupations)', 'Yes (Healthcare Practitioners and Technical Occupations)', 'Yes (Management Occupations)', 'Yes (Protective Service Occupations)', 'Yes (Education, Training, and Library Occupations)', 'Yes (Office and Administrative Support Occupations)', 'Yes (Computer and Mathematical Occupations)', 'Yes (Legal Occupations)', 'Yes (Personal Care and Service Occupations)']
85
+ unique_INTERVENTION = ['No', 'Yes']
86
+ unique_ICP = ['None', 'Intraventricular drain or catheter (e.g. ventriculostomy, external ventricular drain)', 'Intraparenchymal pressure monitor (e.g. Camino bolt, subarachnoid bolt, intraparenchymal catheter)', 'Jugular venous bulb', 'Intraparenchymal oxygen monitor (e.g. Licox)', 'Unknown']
87
+ unique_ALCOHOLSCREEN = ['Yes', 'No', 'Unknown']
88
+ unique_ANTIBIOTICTHERAPY = ['Yes', 'No', 'Unknown']
89
+ unique_DRGSCR_AMPHETAMINE = ['Not tested', 'No', 'Yes']
90
+ unique_DRGSCR_BARBITURATE = ['Not tested', 'No', 'Yes']
91
+ unique_DRGSCR_BENZODIAZEPINES = ['Not tested', 'No', 'Yes']
92
+ unique_DRGSCR_CANNABINOID = ['Not tested', 'No', 'Yes']
93
+ unique_DRGSCR_COCAINE = ['Not tested', 'No', 'Yes']
94
+ unique_DRGSCR_ECSTASY = ['Not tested', 'No', 'Yes']
95
+ unique_DRGSCR_METHADONE = ['Not tested', 'No', 'Yes']
96
+ unique_DRGSCR_METHAMPHETAMINE = ['Not tested', 'No', 'Yes']
97
+ unique_DRGSCR_OPIOID = ['Not tested', 'No', 'Yes']
98
+ unique_DRGSCR_OXYCODONE = ['Not tested', 'No', 'Yes']
99
+ unique_DRGSCR_PHENCYCLIDINE = ['Not tested', 'No', 'Yes']
100
+ unique_DRGSCR_TRICYCLICDEPRESS = ['Not tested', 'No', 'Yes']
101
+ unique_VERIFICATIONLEVEL = ['Level I Trauma Center', 'Level II Trauma Center', 'Level III Trauma Center', 'Unknown']
102
+ unique_HOSPITALTYPE = ['Non-profit', 'For profit', 'Government', 'Unknown']
103
+ unique_BEDSIZE = ['More than 600', '401 to 600', '201 to 400', '200 or fewer']
104
+ unique_PRIMARYMETHODPAYMENT = ['Private/commercial insurance', 'Medicaid', 'Medicare', 'Other government', 'Self-pay', 'Other', 'Not billed', 'Unknown']
105
+
106
+ #Prepare data for the outcome 1 (mortality).
107
+ y1 = x1.pop('OUTCOME')
108
+ categorical_columns1 = list(x1.select_dtypes('object').columns)
109
+ x1 = x1.astype({col: "category" for col in categorical_columns1})
110
+ y1_data_xgb = xgb.DMatrix(x1, label=y1, enable_categorical=True)
111
+ y1_data_lgb = lgb.Dataset(x1, label=y1)
112
+ y1_data_cb = Pool(data=x1, label=y1, cat_features=categorical_columns1)
113
+ x1_rf = x1
114
+ categorical_columns1 = list(x1_rf.select_dtypes('category').columns)
115
+ x1_rf = x1_rf.astype({col: "category" for col in categorical_columns1})
116
+ le = sklearn.preprocessing.LabelEncoder()
117
+ for col in categorical_columns1:
118
+ x1_rf[col] = le.fit_transform(x1_rf[col].astype(str))
119
+ d1 = dict.fromkeys(x1_rf.select_dtypes(np.int64).columns, str)
120
+ x1_rf = x1_rf.astype(d1)
121
+
122
+ #Prepare data for the outcome 2 (Discharge_Disposition).
123
+ y2 = x2.pop('OUTCOME')
124
+ categorical_columns2 = list(x2.select_dtypes('object').columns)
125
+ x2 = x2.astype({col: "category" for col in categorical_columns2})
126
+ y2_data_xgb = xgb.DMatrix(x2, label=y2, enable_categorical=True)
127
+ y2_data_lgb = lgb.Dataset(x2, label=y2)
128
+ y2_data_cb = Pool(data=x2, label=y2, cat_features=categorical_columns2)
129
+ x2_rf = x2
130
+ categorical_columns2 = list(x2_rf.select_dtypes('category').columns)
131
+ x2_rf = x2_rf.astype({col: "category" for col in categorical_columns2})
132
+ le = sklearn.preprocessing.LabelEncoder()
133
+ for col in categorical_columns2:
134
+ x2_rf[col] = le.fit_transform(x2_rf[col].astype(str))
135
+ d2 = dict.fromkeys(x2_rf.select_dtypes(np.int64).columns, str)
136
+ x2_rf = x2_rf.astype(d2)
137
+
138
+ #Prepare data for the outcome 3 (length of stay).
139
+ y3 = x3.pop('OUTCOME')
140
+ categorical_columns3 = list(x3.select_dtypes('object').columns)
141
+ x3 = x3.astype({col: "category" for col in categorical_columns3})
142
+ y3_data_xgb = xgb.DMatrix(x3, label=y3, enable_categorical=True)
143
+ y3_data_lgb = lgb.Dataset(x3, label=y3)
144
+ y3_data_cb = Pool(data=x3, label=y3, cat_features=categorical_columns3)
145
+ x3_rf = x3
146
+ categorical_columns3 = list(x3_rf.select_dtypes('category').columns)
147
+ x3_rf = x3_rf.astype({col: "category" for col in categorical_columns3})
148
+ le = sklearn.preprocessing.LabelEncoder()
149
+ for col in categorical_columns3:
150
+ x3_rf[col] = le.fit_transform(x3_rf[col].astype(str))
151
+ d3 = dict.fromkeys(x3_rf.select_dtypes(np.int64).columns, str)
152
+ x3_rf = x3_rf.astype(d3)
153
+
154
+ #Prepare data for the outcome 4 (ICU length of stay).
155
+ y4 = x4.pop('OUTCOME')
156
+ categorical_columns4 = list(x4.select_dtypes('object').columns)
157
+ x4 = x4.astype({col: "category" for col in categorical_columns4})
158
+ y4_data_xgb = xgb.DMatrix(x4, label=y4, enable_categorical=True)
159
+ y4_data_lgb = lgb.Dataset(x4, label=y4)
160
+ y4_data_cb = Pool(data=x4, label=y4, cat_features=categorical_columns4)
161
+ x4_rf = x4
162
+ categorical_columns4 = list(x4_rf.select_dtypes('category').columns)
163
+ x4_rf = x4_rf.astype({col: "category" for col in categorical_columns4})
164
+ le = sklearn.preprocessing.LabelEncoder()
165
+ for col in categorical_columns4:
166
+ x4_rf[col] = le.fit_transform(x4_rf[col].astype(str))
167
+ d4 = dict.fromkeys(x4_rf.select_dtypes(np.int64).columns, str)
168
+ x4_rf = x4_rf.astype(d4)
169
+
170
+ #Prepare data for the outcome 5 (major complications).
171
+ y5 = x5.pop('OUTCOME')
172
+ categorical_columns5 = list(x5.select_dtypes('object').columns)
173
+ x5 = x5.astype({col: "category" for col in categorical_columns5})
174
+ y5_data_xgb = xgb.DMatrix(x5, label=y5, enable_categorical=True)
175
+ y5_data_lgb = lgb.Dataset(x5, label=y5)
176
+ y5_data_cb = Pool(data=x5, label=y5, cat_features=categorical_columns5)
177
+ x5_rf = x5
178
+ categorical_columns5 = list(x5_rf.select_dtypes('category').columns)
179
+ x5_rf = x5_rf.astype({col: "category" for col in categorical_columns5})
180
+ le = sklearn.preprocessing.LabelEncoder()
181
+ for col in categorical_columns5:
182
+ x5_rf[col] = le.fit_transform(x5_rf[col].astype(str))
183
+ d5 = dict.fromkeys(x5_rf.select_dtypes(np.int64).columns, str)
184
+ x5_rf = x5_rf.astype(d5)
185
+
186
+ #Assign hyperparameters.
187
+ y1_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 0.7463867502190046, 'alpha': 0.0007952683509471142, 'max_depth': 2, 'eta': 0.001938108415188413, 'gamma': 0.23560062559306924, 'grow_policy': 'depthwise'}
188
+ y1_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 9.55209278055602, 'lambda_l2': 9.791473124643204, 'num_leaves': 13, 'feature_fraction': 0.5992658612730835, 'bagging_fraction': 0.43683499843234525, 'bagging_freq': 4, 'min_child_samples': 26}
189
+ y1_cb_params = {'objective': 'CrossEntropy', 'colsample_bylevel': 0.02048734243685444, 'depth': 9, 'boosting_type': 'Ordered', 'bootstrap_type': 'MVS'}
190
+ y1_rf_params = {'criterion': 'gini', 'max_features': 'log2', 'max_depth': 1, 'n_estimators': 700, 'min_samples_leaf': 3, 'min_samples_split': 4}
191
+
192
+ y2_xgb_params = {}
193
+ y2_lgb_params = {}
194
+ y2_cb_params = {}
195
+ y2_rf_params = {}
196
+
197
+ y3_xgb_params = {}
198
+ y3_lgb_params = {}
199
+ y3_cb_params = {}
200
+ y3_rf_params = {}
201
+
202
+ y4_xgb_params = {}
203
+ y4_lgb_params = {}
204
+ y4_cb_params = {}
205
+ y4_rf_params = {}
206
+
207
+ y5_xgb_params = {}
208
+ y5_lgb_params = {}
209
+ y5_cb_params = {}
210
+ y5_rf_params = {}
211
+
212
+
213
+ #Modeling for y1 (mortality).
214
+ y1_model_xgb = xgb.train(params=y1_xgb_params, dtrain=y1_data_xgb)
215
+ y1_explainer_xgb = shap.TreeExplainer(y1_model_xgb)
216
+
217
+ y1_model_lgb = lgb.train(params=y1_lgb_params, train_set=y1_data_lgb)
218
+ y1_explainer_lgb = shap.TreeExplainer(y1_model_lgb)
219
+
220
+ y1_model_cb = cb.train(pool=y1_data_cb, params=y1_cb_params)
221
+ y1_explainer_cb = shap.TreeExplainer(y1_model_cb)
222
+
223
+ from sklearn.ensemble import RandomForestClassifier as rf
224
+ y1_rf = rf(**y1_rf_params)
225
+ y1_model_rf = y1_rf.fit(x1_rf, y1)
226
+ y1_explainer_rf = shap.TreeExplainer(y1_model_rf)
227
+
228
+
229
+ #Modeling for y2 (Discharge_Disposition).
230
+ y2_model_xgb = xgb.train(params=y2_xgb_params, dtrain=y2_data_xgb)
231
+ y2_explainer_xgb = shap.TreeExplainer(y2_model_xgb)
232
+
233
+ y2_model_lgb = lgb.train(params=y2_lgb_params, train_set=y2_data_lgb)
234
+ y2_explainer_lgb = shap.TreeExplainer(y2_model_lgb)
235
+
236
+ y2_model_cb = cb.train(pool=y2_data_cb, params=y2_cb_params)
237
+ y2_explainer_cb = shap.TreeExplainer(y2_model_cb)
238
+
239
+ from sklearn.ensemble import RandomForestClassifier as rf
240
+ y2_rf = rf(**y2_rf_params)
241
+ y2_model_rf = y2_rf.fit(x2_rf, y2)
242
+ y2_explainer_rf = shap.TreeExplainer(y2_model_rf)
243
+
244
+
245
+ #Modeling for y3 (length of stay).
246
+ y3_model_xgb = xgb.train(params=y3_xgb_params, dtrain=y3_data_xgb)
247
+ y3_explainer_xgb = shap.TreeExplainer(y3_model_xgb)
248
+
249
+ y3_model_lgb = lgb.train(params=y3_lgb_params, train_set=y3_data_lgb)
250
+ y3_explainer_lgb = shap.TreeExplainer(y3_model_lgb)
251
+
252
+ y3_model_cb = cb.train(pool=y3_data_cb, params=y3_cb_params)
253
+ y3_explainer_cb = shap.TreeExplainer(y3_model_cb)
254
+
255
+ from sklearn.ensemble import RandomForestClassifier as rf
256
+ y3_rf = rf(**y3_rf_params)
257
+ y3_model_rf = y3_rf.fit(x3_rf, y3)
258
+ y3_explainer_rf = shap.TreeExplainer(y3_model_rf)
259
+
260
+ #Modeling for y4 (ICU length of stay).
261
+ y4_model_xgb = xgb.train(params=y4_xgb_params, dtrain=y4_data_xgb)
262
+ y4_explainer_xgb = shap.TreeExplainer(y4_model_xgb)
263
+
264
+ y4_model_lgb = lgb.train(params=y4_lgb_params, train_set=y4_data_lgb)
265
+ y4_explainer_lgb = shap.TreeExplainer(y4_model_lgb)
266
+
267
+ y4_model_cb = cb.train(pool=y4_data_cb, params=y4_cb_params)
268
+ y4_explainer_cb = shap.TreeExplainer(y4_model_cb)
269
+
270
+ from sklearn.ensemble import RandomForestClassifier as rf
271
+ y4_rf = rf(**y4_rf_params)
272
+ y4_model_rf = y4_rf.fit(x4_rf, y4)
273
+ y4_explainer_rf = shap.TreeExplainer(y4_model_rf)
274
+
275
+ #Modeling for y5 (major complications).
276
+ y5_model_xgb = xgb.train(params=y5_xgb_params, dtrain=y5_data_xgb)
277
+ y5_explainer_xgb = shap.TreeExplainer(y5_model_xgb)
278
+
279
+ y5_model_lgb = lgb.train(params=y5_lgb_params, train_set=y5_data_lgb)
280
+ y5_explainer_lgb = shap.TreeExplainer(y5_model_lgb)
281
+
282
+ y5_model_cb = cb.train(pool=y5_data_cb, params=y5_cb_params)
283
+ y5_explainer_cb = shap.TreeExplainer(y5_model_cb)
284
+
285
+ from sklearn.ensemble import RandomForestClassifier as rf
286
+ y5_rf = rf(**y5_rf_params)
287
+ y5_model_rf = y5_rf.fit(x5_rf, y5)
288
+ y5_explainer_rf = shap.TreeExplainer(y5_model_rf)
289
+
290
+ #Define predict for y1 (mortality).
291
+ def y1_predict_xgb(*args):
292
+ df_xgb = pd.DataFrame([args], columns=x1.columns)
293
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns1})
294
+ pos_pred = y1_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
295
+ return {"Mortality": float(pos_pred[0]), "No Mortality": 1 - float(pos_pred[0])}
296
+
297
+ def y1_predict_lgb(*args):
298
+ df = pd.DataFrame([args], columns=data.columns)
299
+ df = df.astype({col: "category" for col in categorical_columns1})
300
+ pos_pred = y1_model_lgb.predict(df)
301
+ return {"Mortality": float(pos_pred[0]), "No Mortality": 1 - float(pos_pred[0])}
302
+
303
+ def y1_predict_cb(*args):
304
+ df_cb = pd.DataFrame([args], columns=x1.columns)
305
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns1})
306
+ pos_pred = y1_model_cb.predict(Pool(df_cb, cat_features = categorical_columns1), prediction_type='Probability')
307
+ return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}
308
+
309
+ def y1_predict_rf(*args):
310
+ df = pd.DataFrame([args], columns=x1_rf.columns)
311
+ df = df.astype({col: "category" for col in categorical_columns1})
312
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
313
+ df = df.astype(d)
314
+ pos_pred = y1_model_rf.predict_proba(df)
315
+ return {"Mortality": float(pos_pred[0][1]), "Home Discharge": float(pos_pred[0][0])}
316
+
317
+ #Define predict for y2 (Discharge_Disposition).
318
+ def y2_predict_xgb(*args):
319
+ df_xgb = pd.DataFrame([args], columns=x2.columns)
320
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns2})
321
+ pos_pred = y2_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
322
+ return {"Facility Discharge": float(pos_pred[0]), "Home Discharge": 1 - float(pos_pred[0])}
323
+
324
+ def y2_predict_lgb(*args):
325
+ df = pd.DataFrame([args], columns=data.columns)
326
+ df = df.astype({col: "category" for col in categorical_columns2})
327
+ pos_pred = y2_model_lgb.predict(df)
328
+ return {"Facility Discharge": float(pos_pred[0]), "Home Discharge": 1 - float(pos_pred[0])}
329
+
330
+ def y2_predict_cb(*args):
331
+ df_cb = pd.DataFrame([args], columns=x2.columns)
332
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns2})
333
+ pos_pred = y2_model_cb.predict(Pool(df_cb, cat_features = categorical_columns2), prediction_type='Probability')
334
+ return {"Facility Discharge": float(pos_pred[0][1]), "Home Discharge": float(pos_pred[0][0])}
335
+
336
+ def y2_predict_rf(*args):
337
+ df = pd.DataFrame([args], columns=x2_rf.columns)
338
+ df = df.astype({col: "category" for col in categorical_columns2})
339
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
340
+ df = df.astype(d)
341
+ pos_pred = y2_model_rf.predict_proba(df)
342
+ return {"Facility Discharge": float(pos_pred[0][1]), "No Prolonged LOS": float(pos_pred[0][0])}
343
+
344
+ #Define predict for y3 (length of stay).
345
+ def y3_predict_xgb(*args):
346
+ df_xgb = pd.DataFrame([args], columns=x3.columns)
347
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns3})
348
+ pos_pred = y3_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
349
+ return {"Prolonged LOS": float(pos_pred[0]), "No Prolonged LOS": 1 - float(pos_pred[0])}
350
+
351
+ def y3_predict_lgb(*args):
352
+ df = pd.DataFrame([args], columns=data.columns)
353
+ df = df.astype({col: "category" for col in categorical_columns3})
354
+ pos_pred = y3_model_lgb.predict(df)
355
+ return {"Prolonged LOS": float(pos_pred[0]), "No Prolonged LOS": 1 - float(pos_pred[0])}
356
+
357
+ def y3_predict_cb(*args):
358
+ df_cb = pd.DataFrame([args], columns=x3.columns)
359
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns3})
360
+ pos_pred = y3_model_cb.predict(Pool(df_cb, cat_features = categorical_columns3), prediction_type='Probability')
361
+ return {"Prolonged LOS": float(pos_pred[0][1]), "No Prolonged LOS": float(pos_pred[0][0])}
362
+
363
+ def y3_predict_rf(*args):
364
+ df = pd.DataFrame([args], columns=x3_rf.columns)
365
+ df = df.astype({col: "category" for col in categorical_columns3})
366
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
367
+ df = df.astype(d)
368
+ pos_pred = y3_model_rf.predict_proba(df)
369
+ return {"Prolonged LOS": float(pos_pred[0][1]), "No Prolonged LOS": float(pos_pred[0][0])}
370
+
371
+ #Define predict for y4 (ICU length of stay).
372
+ def y4_predict_xgb(*args):
373
+ df_xgb = pd.DataFrame([args], columns=x4.columns)
374
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns4})
375
+ pos_pred = y4_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
376
+ return {"Prolonged ICU LOS": float(pos_pred[0]), "No Prolonged ICU LOS": 1 - float(pos_pred[0])}
377
+
378
+ def y4_predict_lgb(*args):
379
+ df = pd.DataFrame([args], columns=data.columns)
380
+ df = df.astype({col: "category" for col in categorical_columns4})
381
+ pos_pred = y4_model_lgb.predict(df)
382
+ return {"Prolonged ICU LOS": float(pos_pred[0]), "No Prolonged ICU LOS": 1 - float(pos_pred[0])}
383
+
384
+ def y4_predict_cb(*args):
385
+ df_cb = pd.DataFrame([args], columns=x4.columns)
386
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns4})
387
+ pos_pred = y4_model_cb.predict(Pool(df_cb, cat_features = categorical_columns4), prediction_type='Probability')
388
+ return {"Prolonged ICU LOS": float(pos_pred[0][1]), "No Prolonged ICU LOS": float(pos_pred[0][0])}
389
+
390
+ def y4_predict_rf(*args):
391
+ df = pd.DataFrame([args], columns=x4_rf.columns)
392
+ df = df.astype({col: "category" for col in categorical_columns4})
393
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
394
+ df = df.astype(d)
395
+ pos_pred = y4_model_rf.predict_proba(df)
396
+ return {"Prolonged ICU LOS": float(pos_pred[0][1]), "No Prolonged ICU LOS": float(pos_pred[0][0])}
397
+
398
+ #Define predict for y5 (major complications).
399
+ def y5_predict_xgb(*args):
400
+ df_xgb = pd.DataFrame([args], columns=x5.columns)
401
+ df_xgb = df_xgb.astype({col: "category" for col in categorical_columns5})
402
+ pos_pred = y5_model_xgb.predict(xgb.DMatrix(df_xgb, enable_categorical=True))
403
+ return {"Major Complications": float(pos_pred[0]), "No Major Complications": 1 - float(pos_pred[0])}
404
+
405
+ def y5_predict_lgb(*args):
406
+ df = pd.DataFrame([args], columns=data.columns)
407
+ df = df.astype({col: "category" for col in categorical_columns5})
408
+ pos_pred = y5_model_lgb.predict(df)
409
+ return {"Major Complications": float(pos_pred[0]), "No Major Complications": 1 - float(pos_pred[0])}
410
+
411
+ def y5_predict_cb(*args):
412
+ df_cb = pd.DataFrame([args], columns=x5.columns)
413
+ df_cb = df_cb.astype({col: "category" for col in categorical_columns5})
414
+ pos_pred = y5_model_cb.predict(Pool(df_cb, cat_features = categorical_columns5), prediction_type='Probability')
415
+ return {"Major Complications": float(pos_pred[0][1]), "No Major Complications": float(pos_pred[0][0])}
416
+
417
+ def y5_predict_rf(*args):
418
+ df = pd.DataFrame([args], columns=x5_rf.columns)
419
+ df = df.astype({col: "category" for col in categorical_columns5})
420
+ d = dict.fromkeys(df.select_dtypes(np.int64).columns, np.int32)
421
+ df = df.astype(d)
422
+ pos_pred = y5_model_rf.predict_proba(df)
423
+ return {"Major Complications": float(pos_pred[0][1]), "No Major Complications": float(pos_pred[0][0])}
424
+
425
+
426
+ #Define interpret for y1 (mortality).
427
+ def y1_interpret_xgb(*args):
428
+ df = pd.DataFrame([args], columns=x1.columns)
429
+ df = df.astype({col: "category" for col in categorical_columns1})
430
+ shap_values = y1_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
431
+ scores_desc = list(zip(shap_values[0], x1.columns))
432
+ scores_desc = sorted(scores_desc)
433
+ fig_m = plt.figure(facecolor='white')
434
+ fig_m.set_size_inches(14, 10)
435
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
436
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
437
+ plt.yticks(fontsize=12)
438
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
439
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
440
+ return fig_m
441
+
442
+ def y1_interpret_lgb(*args):
443
+ df = pd.DataFrame([args], columns=x1.columns)
444
+ df = df.astype({col: "category" for col in categorical_columns1})
445
+ shap_values = y1_explainer_lgb.shap_values(df)
446
+ scores_desc = list(zip(shap_values[0][0], x1.columns))
447
+ scores_desc = sorted(scores_desc)
448
+ fig_m = plt.figure(facecolor='white')
449
+ fig_m.set_size_inches(14, 10)
450
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
451
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
452
+ plt.yticks(fontsize=12)
453
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
454
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
455
+ return fig_m
456
+
457
+ def y1_interpret_cb(*args):
458
+ df = pd.DataFrame([args], columns=x1.columns)
459
+ df = df.astype({col: "category" for col in categorical_columns1})
460
+ shap_values = y1_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns1))
461
+ scores_desc = list(zip(shap_values[0], x1.columns))
462
+ scores_desc = sorted(scores_desc)
463
+ fig_m = plt.figure(facecolor='white')
464
+ fig_m.set_size_inches(14, 10)
465
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
466
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
467
+ plt.yticks(fontsize=12)
468
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
469
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
470
+ return fig_m
471
+
472
+ def y1_interpret_rf(*args):
473
+ df = pd.DataFrame([args], columns=x1_rf.columns)
474
+ df = df.astype({col: "category" for col in categorical_columns1})
475
+ shap_values = y1_explainer_rf.shap_values(df)
476
+ scores_desc = list(zip(shap_values[0][0], x1_rf.columns))
477
+ scores_desc = sorted(scores_desc)
478
+ fig_m = plt.figure(facecolor='white')
479
+ fig_m.set_size_inches(14, 10)
480
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
481
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
482
+ plt.yticks(fontsize=12)
483
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
484
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
485
+ return fig_m
486
+
487
+ #Define interpret for y2 (Discharge_Disposition).
488
+ def y2_interpret_xgb(*args):
489
+ df = pd.DataFrame([args], columns=x2.columns)
490
+ df = df.astype({col: "category" for col in categorical_columns2})
491
+ shap_values = y2_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
492
+ scores_desc = list(zip(shap_values[0], x2.columns))
493
+ scores_desc = sorted(scores_desc)
494
+ fig_m = plt.figure(facecolor='white')
495
+ fig_m.set_size_inches(14, 10)
496
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
497
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
498
+ plt.yticks(fontsize=12)
499
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
500
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
501
+ return fig_m
502
+
503
+ def y2_interpret_lgb(*args):
504
+ df = pd.DataFrame([args], columns=x2.columns)
505
+ df = df.astype({col: "category" for col in categorical_columns2})
506
+ shap_values = y2_explainer_lgb.shap_values(df)
507
+ scores_desc = list(zip(shap_values[0][0], x2.columns))
508
+ scores_desc = sorted(scores_desc)
509
+ fig_m = plt.figure(facecolor='white')
510
+ fig_m.set_size_inches(14, 10)
511
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
512
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
513
+ plt.yticks(fontsize=12)
514
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
515
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
516
+ return fig_m
517
+
518
+ def y2_interpret_cb(*args):
519
+ df = pd.DataFrame([args], columns=x2.columns)
520
+ df = df.astype({col: "category" for col in categorical_columns2})
521
+ shap_values = y2_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns2))
522
+ scores_desc = list(zip(shap_values[0], x2.columns))
523
+ scores_desc = sorted(scores_desc)
524
+ fig_m = plt.figure(facecolor='white')
525
+ fig_m.set_size_inches(14, 10)
526
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
527
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
528
+ plt.yticks(fontsize=12)
529
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
530
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
531
+ return fig_m
532
+
533
+ def y2_interpret_rf(*args):
534
+ df = pd.DataFrame([args], columns=x2_rf.columns)
535
+ df = df.astype({col: "category" for col in categorical_columns2})
536
+ shap_values = y2_explainer_rf.shap_values(df)
537
+ scores_desc = list(zip(shap_values[0][0], x2_rf.columns))
538
+ scores_desc = sorted(scores_desc)
539
+ fig_m = plt.figure(facecolor='white')
540
+ fig_m.set_size_inches(14, 10)
541
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
542
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
543
+ plt.yticks(fontsize=12)
544
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
545
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
546
+ return fig_m
547
+
548
+ #Define interpret for y3 (length of stay).
549
+ def y3_interpret_xgb(*args):
550
+ df = pd.DataFrame([args], columns=x3.columns)
551
+ df = df.astype({col: "category" for col in categorical_columns3})
552
+ shap_values = y3_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
553
+ scores_desc = list(zip(shap_values[0], x3.columns))
554
+ scores_desc = sorted(scores_desc)
555
+ fig_m = plt.figure(facecolor='white')
556
+ fig_m.set_size_inches(14, 10)
557
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
558
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
559
+ plt.yticks(fontsize=12)
560
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
561
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
562
+ return fig_m
563
+
564
+ def y3_interpret_lgb(*args):
565
+ df = pd.DataFrame([args], columns=x3.columns)
566
+ df = df.astype({col: "category" for col in categorical_columns3})
567
+ shap_values = y3_explainer_lgb.shap_values(df)
568
+ scores_desc = list(zip(shap_values[0][0], x3.columns))
569
+ scores_desc = sorted(scores_desc)
570
+ fig_m = plt.figure(facecolor='white')
571
+ fig_m.set_size_inches(14, 10)
572
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
573
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
574
+ plt.yticks(fontsize=12)
575
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
576
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
577
+ return fig_m
578
+
579
+ def y3_interpret_cb(*args):
580
+ df = pd.DataFrame([args], columns=x3.columns)
581
+ df = df.astype({col: "category" for col in categorical_columns3})
582
+ shap_values = y3_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns3))
583
+ scores_desc = list(zip(shap_values[0], x3.columns))
584
+ scores_desc = sorted(scores_desc)
585
+ fig_m = plt.figure(facecolor='white')
586
+ fig_m.set_size_inches(14, 10)
587
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
588
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
589
+ plt.yticks(fontsize=12)
590
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
591
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
592
+ return fig_m
593
+
594
+ def y3_interpret_rf(*args):
595
+ df = pd.DataFrame([args], columns=x3_rf.columns)
596
+ df = df.astype({col: "category" for col in categorical_columns3})
597
+ shap_values = y3_explainer_rf.shap_values(df)
598
+ scores_desc = list(zip(shap_values[0][0], x3_rf.columns))
599
+ scores_desc = sorted(scores_desc)
600
+ fig_m = plt.figure(facecolor='white')
601
+ fig_m.set_size_inches(14, 10)
602
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
603
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
604
+ plt.yticks(fontsize=12)
605
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
606
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
607
+ return fig_m
608
+
609
+ #Define interpret for y4 (ICU length of stay).
610
+ def y4_interpret_xgb(*args):
611
+ df = pd.DataFrame([args], columns=x4.columns)
612
+ df = df.astype({col: "category" for col in categorical_columns4})
613
+ shap_values = y4_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
614
+ scores_desc = list(zip(shap_values[0], x4.columns))
615
+ scores_desc = sorted(scores_desc)
616
+ fig_m = plt.figure(facecolor='white')
617
+ fig_m.set_size_inches(14, 10)
618
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
619
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
620
+ plt.yticks(fontsize=12)
621
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
622
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
623
+ return fig_m
624
+
625
+ def y4_interpret_lgb(*args):
626
+ df = pd.DataFrame([args], columns=x4.columns)
627
+ df = df.astype({col: "category" for col in categorical_columns4})
628
+ shap_values = y4_explainer_lgb.shap_values(df)
629
+ scores_desc = list(zip(shap_values[0][0], x4.columns))
630
+ scores_desc = sorted(scores_desc)
631
+ fig_m = plt.figure(facecolor='white')
632
+ fig_m.set_size_inches(14, 10)
633
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
634
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
635
+ plt.yticks(fontsize=12)
636
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
637
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
638
+ return fig_m
639
+
640
+ def y4_interpret_cb(*args):
641
+ df = pd.DataFrame([args], columns=x4.columns)
642
+ df = df.astype({col: "category" for col in categorical_columns4})
643
+ shap_values = y4_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns4))
644
+ scores_desc = list(zip(shap_values[0], x4.columns))
645
+ scores_desc = sorted(scores_desc)
646
+ fig_m = plt.figure(facecolor='white')
647
+ fig_m.set_size_inches(14, 10)
648
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
649
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
650
+ plt.yticks(fontsize=12)
651
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
652
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
653
+ return fig_m
654
+
655
+ def y4_interpret_rf(*args):
656
+ df = pd.DataFrame([args], columns=x4_rf.columns)
657
+ df = df.astype({col: "category" for col in categorical_columns4})
658
+ shap_values = y4_explainer_rf.shap_values(df)
659
+ scores_desc = list(zip(shap_values[0][0], x4_rf.columns))
660
+ scores_desc = sorted(scores_desc)
661
+ fig_m = plt.figure(facecolor='white')
662
+ fig_m.set_size_inches(14, 10)
663
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
664
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
665
+ plt.yticks(fontsize=12)
666
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
667
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
668
+ return fig_m
669
+
670
+ #Define interpret for y5 (major complications).
671
+ def y5_interpret_xgb(*args):
672
+ df = pd.DataFrame([args], columns=x5.columns)
673
+ df = df.astype({col: "category" for col in categorical_columns5})
674
+ shap_values = y5_explainer_xgb.shap_values(xgb.DMatrix(df, enable_categorical=True))
675
+ scores_desc = list(zip(shap_values[0], x5.columns))
676
+ scores_desc = sorted(scores_desc)
677
+ fig_m = plt.figure(facecolor='white')
678
+ fig_m.set_size_inches(14, 10)
679
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
680
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
681
+ plt.yticks(fontsize=12)
682
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
683
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
684
+ return fig_m
685
+
686
+ def y5_interpret_lgb(*args):
687
+ df = pd.DataFrame([args], columns=x5.columns)
688
+ df = df.astype({col: "category" for col in categorical_columns5})
689
+ shap_values = y5_explainer_lgb.shap_values(df)
690
+ scores_desc = list(zip(shap_values[0][0], x5.columns))
691
+ scores_desc = sorted(scores_desc)
692
+ fig_m = plt.figure(facecolor='white')
693
+ fig_m.set_size_inches(14, 10)
694
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
695
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
696
+ plt.yticks(fontsize=12)
697
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
698
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
699
+ return fig_m
700
+
701
+ def y5_interpret_cb(*args):
702
+ df = pd.DataFrame([args], columns=x5.columns)
703
+ df = df.astype({col: "category" for col in categorical_columns5})
704
+ shap_values = y5_explainer_cb.shap_values(Pool(df, cat_features = categorical_columns5))
705
+ scores_desc = list(zip(shap_values[0], x5.columns))
706
+ scores_desc = sorted(scores_desc)
707
+ fig_m = plt.figure(facecolor='white')
708
+ fig_m.set_size_inches(14, 10)
709
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
710
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
711
+ plt.yticks(fontsize=12)
712
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
713
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
714
+ return fig_m
715
+
716
+ def y5_interpret_rf(*args):
717
+ df = pd.DataFrame([args], columns=x5_rf.columns)
718
+ df = df.astype({col: "category" for col in categorical_columns5})
719
+ shap_values = y5_explainer_rf.shap_values(df)
720
+ scores_desc = list(zip(shap_values[0][0], x5_rf.columns))
721
+ scores_desc = sorted(scores_desc)
722
+ fig_m = plt.figure(facecolor='white')
723
+ fig_m.set_size_inches(14, 10)
724
+ plt.barh([s[1] for s in scores_desc], [s[0] for s in scores_desc])
725
+ plt.title("Feature Shap Values", fontsize = 24, pad = 20, fontweight = 'bold')
726
+ plt.yticks(fontsize=12)
727
+ plt.xlabel("Shap Value", fontsize = 16, labelpad=8, fontweight = 'bold')
728
+ plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
729
+ return fig_m
730
+
731
+ with gr.Blocks(title = "NTDB-Epidural") as demo:
732
+
733
+ gr.Markdown(
734
+ """
735
+ """
736
+ )
737
+
738
+ gr.Markdown(
739
+ """
740
+ # Prediction Tool
741
+
742
+ ## Epidural Hematoma Outcomes
743
+
744
+ **The publication describing the details of this predictive tool will be posted here upon the acceptance of publication.**
745
+
746
+ ### Disclaimer
747
+
748
+ The American College of Surgeons National Trauma Data Bank (ACS-NTDB) and the hospitals participating in the ACS-NTDB 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.
749
+
750
+ 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.
751
+
752
+ 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.
753
+
754
+ 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.
755
+
756
+ 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.
757
+
758
+ By using this tool, you accept all of the above terms.
759
+
760
+ """
761
+ )
762
+
763
+ with gr.Row():
764
+
765
+ with gr.Column():
766
+
767
+ Age = gr.Slider(label="Age", minimum = 18, maximum = 99, step = 1, value = 37)
768
+
769
+ Sex = gr.Radio(label = "Sex", choices = unique_SEX, type = 'Male')
770
+
771
+ Race = gr.Radio(label = "Race", choices = unique_RACE, type = 'index', value = 'White')
772
+
773
+ Ethnicity = gr.Radio(label = "Ethnicity", choices = unique_ETHNICITY, type = 'index',value = 'Not Hispanic or Latino')
774
+
775
+ Weight = gr.Slider(label = "Weight (in kilograms)", minimum = 20, maximum = 200, step = 1, value = 75)
776
+
777
+ Height = gr.Slider(label = "Height (in centimeters)", minimum = 100, maximum = 250, step = 1, value = 175)
778
+
779
+ Systolic_Blood_Pressure = gr.Slider(label = "Systolic Blood Pressure", minimum = 50, maximum = 2.25, step = 1, value = 135)
780
+
781
+ Pulse_Rate = gr.Slider(label = "Pulse Rate", minimum=20, maximum=250, step=1, value = 250)
782
+
783
+ Supplemental_Oxygen = gr.Radio(label = "Supplemental Oxygen", choices = unique_SUPPLEMENTALOXYGEN, type = 'index', value = 'No supplemental oxygen')
784
+
785
+ Pulse_Oximetry = gr.Slider(label = "Pulse Oximetry", minimum = 50, maximum = 100, step = 1, value = 99)
786
+
787
+ Respiratory_Assistance = gr.Radio(label = "Respiratory Assistance", choices = unique_RESPIRATORYASSISTANCE, type = 'index', value = 'Unassisted respiratory rate')
788
+
789
+ Respiratory_Rate = gr.Slider(label = "Respiratory Rate", minimum = 1, maximum = 99, step = 1, value = 18)
790
+
791
+ Temperature = gr.Slider(label = "Temperature", minimum = 30, maximum = 50, step = 0.1, value = 36.5)
792
+
793
+ PreHospital_Cardiac_Arrest = gr.Radio(label = "Pre-Hospital Cardiac Arrest", choices = unique_PREHOSPITALCARDIACARREST, type = 'index', value = 'No')
794
+
795
+ GCS__Eye = gr.Slider(label = "GCS - Eye", minimum = 1, maximum = 4, step = 1, value = 4)
796
+
797
+ GCS__Verbal = gr.Slider(label = "GCS - Verbal", minimum = 1, maximum = 5, step = 1, value = 5)
798
+
799
+ GCS__Motor = gr.Slider(label = "GCS - Motor", minimum = 1, maximum = 6, step = 1, value = 6)
800
+
801
+ Total_GCS = GCS__Eye + GCS__Verbal + GCS__Motor
802
+
803
+ Pupillary_Response = gr.Radio(label = "Pupillary Response", choices = unique_TBIPUPILLARYRESPONSE, type = 'index', value = 'Both reactive')
804
+
805
+ Midline_Shift = gr.Radio(label = "Midline Shift", choices = unique_TBIMIDLINESHIFT, type = 'index', value = 'No')
806
+
807
+ Current_Smoker = gr.Radio(label = "Current Smoker", choices = unique_CC_SMOKING, type = 'index', value = 'No')
808
+
809
+ Comorbid_Condition__Alcohol_Use_Disorder = gr.Radio(label = "Comorbid Condition - Alcohol Use Disorder", choices = unique_CC_ALCOHOLISM, type = 'index', value = 'No')
810
+
811
+ Comorbid_Condition__Substance_Abuse_Disorder = gr.Radio(label = "Comorbid Condition - Substance Abuse Disorder", choices = unique_CC_SUBSTANCEABUSE, type = 'index', value = 'No')
812
+
813
+ Comorbid_Condition__Diabetes_Mellitus = gr.Radio(label = "Comorbid Condition - Diabetes Mellitus", choices = unique_CC_DIABETES, type = 'index', value = 'No')
814
+
815
+ Comorbid_Condition__Hypertension = gr.Radio(label = "Comorbid Condition - Hypertension", choices = unique_CC_HYPERTENSION, type = 'index', value = 'No')
816
+
817
+ Comorbid_Condition__Congestive_Heart_Failure = gr.Radio(label = "Comorbid Condition - Congestive Heart Failure", choices = unique_CC_CHF, type = 'index', value = 'No')
818
+
819
+ History_of_Myocardial_Infarction = gr.Radio(label = "History of Myocardial Infarction", choices = unique_CC_MI, type = 'index', value = 'No')
820
+
821
+ Comorbid_Condition__Angina_Pectoris = gr.Radio(label = "Comorbid Condition - Angina Pectoris", choices = unique_CC_ANGINAPECTORIS, type = 'index', value = 'No')
822
+
823
+ History_of_Cerebrovascular_Accident = gr.Radio(label = "History of Cerebrovascular Accident", choices = unique_CC_CVA, type = 'index', value = 'No')
824
+
825
+ Comorbid_Condition__Peripheral_Arterial_Disease = gr.Radio(label = "Comorbid Condition - Peripheral Arterial Disease", choices = unique_CC_PAD, type = 'index', value = 'No')
826
+
827
+ Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease = gr.Radio(label = "Comorbid Condition - Chronic Obstructive Pulmonary Disease", choices = unique_CC_COPD, type = 'index', value = 'No')
828
+
829
+ Comorbid_Condition__Chronic_Renal_Failure = gr.Radio(label = "Comorbid Condition - Chronic Renal Failure", choices = unique_CC_RENAL, type = 'index', value = 'No')
830
+
831
+ Comorbid_Condition__Cirrhosis = gr.Radio(label = "Comorbid Condition - Cirrhosis", choices = unique_CC_CIRRHOSIS, type = 'index', value = 'No')
832
+
833
+ Comorbid_Condition__Bleeding_Disorder = gr.Radio(label = "Comorbid Condition - Bleeding Disorder", choices = unique_CC_BLEEDING, type = 'index', value = 'No')
834
+
835
+ Comorbid_Condition__Disseminated_Cancer = gr.Radio(label = "Comorbid Condition - Disseminated Cancer", choices = unique_CC_DISCANCER, type = 'index', value = 'No')
836
+
837
+ Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer = gr.Radio(label = "Comorbid Condition - Currently Receiving Chemotherapy for Cancer", choices = unique_CC_CHEMO, type = 'index', value = 'No')
838
+
839
+ Comorbid_Condition__Dementia = gr.Radio(label = "Comorbid Condition - Dementia", choices = unique_CC_DEMENTIA, type = 'index', value = 'xxx')
840
+
841
+ Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder = gr.Radio(label = "Comorbid Condition - Attention Deficit Disorder or Attention Deficit Hyperactivity Disorder", choices = unique_CC_ADHD, type = 'index', value = 'No')
842
+
843
+ Comorbid_Condition__Mental_or_Personality_Disorder = gr.Radio(label = "Comorbid Condition - Mental or Personality Disorder", choices = unique_CC_MENTALPERSONALITY, type = 'index', value = 'No')
844
+
845
+ Ability_to_Complete_AgeAppropriate_ADL = gr.Radio(label = "Ability to Complete Age-Appropriate ADL", choices = unique_CC_FUNCTIONAL, type = 'index', value = 'Yes')
846
+
847
+ Pregnancy = gr.Radio(label = "Pregnancy", choices = unique_CC_PREGNANCY, type = 'index', value = 'No')
848
+
849
+ Anticoagulant_Therapy = gr.Radio(label = "Anticoagulant Therapy", choices = unique_CC_ANTICOAGULANT, type = 'index', value = 'No')
850
+
851
+ Steroid_Use = gr.Radio(label = "Steroid Use", choices = unique_CC_STEROID, type = 'index', value = 'xxx')
852
+
853
+ Advanced_Directive_Limiting_Care = gr.Radio(label = "Advanced Directive Limiting Care", choices = unique_CC_ADLC, type = 'index', value = 'No')
854
+
855
+ Transport_Mode = gr.Radio(label = "Transport Mode", choices = unique_TRANSPORTMODE, type = 'index', value = 'Ground ambulance')
856
+
857
+ InterFacility_Transfer = gr.Radio(label = "Inter-Facility Transfer", choices = unique_INTERFACILITYTRANSFER, type = 'index', value = 'No')
858
+
859
+ Trauma_Type = gr.Radio(label = "Trauma Type", choices = unique_TRAUMATYPE, type = 'index', value = 'Blunt')
860
+
861
+ Injury_Intent = gr.Radio(label = "Injury Intent", choices = unique_INTENT, type = 'index', value = 'Unintentional')
862
+
863
+ Mechanism_of_Injury = gr.Dropdown(label = "Mechanism of Injury", choices = unique_MECHANISM, type = 'index', value = 'Fall')
864
+
865
+ Protective_Device = gr.Dropdown(label = "Protective Device", choices = xxx, type = 'index', value = 'None')
866
+
867
+ WorkRelated = gr.Dropdown(label = "Work-Related", choices = unique_PROTDEV, type = 'index', value = 'No')
868
+
869
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Head = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Head", minimum = 0, maximum = 9, step = 1, value = 1)
870
+
871
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Face = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Face", minimum = 0, maximum = 9, step = 1, value = 1)
872
+
873
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Neck = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Neck", minimum = 0, maximum = 9, step = 1, value = 0)
874
+
875
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Thorax = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Thorax", minimum = 0, maximum = 9, step = 1, value = 0)
876
+
877
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Abdomen = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Abdomen", minimum = 0, maximum = 9, step = 1, value = 0)
878
+
879
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Spine = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Spine", minimum = 0, maximum = 9, step = 1, value = 0)
880
+
881
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Upper_Extremity = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Upper Extremity", minimum = 0, maximum = 9, step = 1, value = 0)
882
+
883
+ AIS_Severity__Maximum_Severity_of_Injury_in_the_Lower_Extremity = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in the Lower Extremity", minimum = 0, maximum = 9, step = 1, value = 0)
884
+
885
+ AIS_Severity__Maximum_Severity_of_Injury_in_Unspecified_Body_Regions = gr.Slider(label = "AIS Severity - Maximum Severity of Injury in Unspecified Body Regions", minimum = 0, maximum = 9, step = 1, value = 0)
886
+
887
+ AIS_derived_ISS = gr.Slider(label="AIS derived ISS", minimum = 1, maximum = 75, step = 1, value = 1)
888
+
889
+ Blood_Transfusion = gr.Slider(label="Blood Transfusion", minimum = 0, maximum = 5000, step = 50, value = 0)
890
+
891
+ Neurosurgical_Intervention = gr.Radio(label = "Neurosurgical Intervention", choices = unique_INTERVENTION, type = 'index', value = 'No')
892
+
893
+ Cerebral_Monitoring = gr.Dropdown(label = "Cerebral Monitoring", choices = unique_ICP, type = 'index', value = 'None')
894
+
895
+ Alcohol_Screen = gr.Radio(label = "Alcohol Screen", choices = unique_ALCOHOLSCREEN, type = 'index', value = 'xxx')
896
+
897
+ Alcohol_Screen_Result = gr.Slider(label="Alcohol Screen Result", minimum = 0, maximum = 1, step = 0.1, value = 0)
898
+
899
+ Drug_Screen__Amphetamine = gr.Radio(label = "Drug Screen - Amphetamine", choices = unique_DRGSCR_AMPHETAMINE, type = 'index', value = 'No')
900
+
901
+ Drug_Screen__Barbiturate = gr.Radio(label = "Drug Screen - Barbiturate", choices = unique_DRGSCR_BARBITURATE, type = 'index', value = 'No')
902
+
903
+ Drug_Screen__Benzodiazepines = gr.Radio(label = "Drug Screen - Benzodiazepines", choices = unique_DRGSCR_BENZODIAZEPINES, type = 'index', value = 'No')
904
+
905
+ Drug_Screen__Cannabinoid = gr.Radio(label = "Drug Screen - Cannabinoid", choices = unique_DRGSCR_CANNABINOID, type = 'index', value = 'No')
906
+
907
+ Drug_Screen__Cocaine = gr.Radio(label = "Drug Screen - Cocaine", choices = unique_DRGSCR_COCAINE, type = 'index', value = 'No')
908
+
909
+ Drug_Screen__MDMA_or_Ecstasy = gr.Radio(label = "Drug Screen - MDMA or Ecstasy", choices = unique_DRGSCR_ECSTASY, type = 'index', value = 'No')
910
+
911
+ Drug_Screen__Methadone = gr.Radio(label = "Drug Screen - Methadone", choices = unique_DRGSCR_METHADONE, type = 'index', value = 'No')
912
+
913
+ Drug_Screen__Methamphetamine = gr.Radio(label = "Drug Screen - Methamphetamine", choices = unique_DRGSCR_METHAMPHETAMINE, type = 'index', value = 'No')
914
+
915
+ Drug_Screen__Opioid = gr.Radio(label = "Drug Screen - Opioid", choices = unique_DRGSCR_OPIOID, type = 'index', value = 'No')
916
+
917
+ Drug_Screen__Oxycodone = gr.Radio(label = "Drug Screen - Oxycodone", choices = unique_DRGSCR_OXYCODONE, type = 'index', value = 'No')
918
+
919
+ Drug_Screen__Phencyclidine = gr.Radio(label = "Drug Screen - Phencyclidine", choices = unique_DRGSCR_PHENCYCLIDINE, type = 'index', value = 'No')
920
+
921
+ Drug_Screen__Tricyclic_Antidepressant = gr.Radio(label = "Drug Screen - Tricyclic Antidepressant", choices = unique_DRGSCR_TRICYCLICDEPRESS, type = 'index', value = 'No')
922
+
923
+ ACS_Verification_Level = gr.Radio(label = "ACS Verification Level", choices = unique_VERIFICATIONLEVEL, type = 'index', value = 'No')
924
+
925
+ Hospital_Type = gr.Radio(label = "Hospital Type", choices = unique_HOSPITALTYPE, type = 'index', value = 'No')
926
+
927
+ Facility_Bed_Size = gr.Radio(label = "Facility Bed Size", choices = unique_BEDSIZE, type = 'index', value = 'More than 600')
928
+
929
+ Primary_Method_of_Payment = gr.Dropdown(label = "Primary Method of Payment", choices = unique_PRIMARYMETHODPAYMENT, type = 'index', value = 'Private/commercial insurance')
930
+
931
+ with gr.Column():
932
+
933
+ with gr.Box():
934
+
935
+ with gr.Row():
936
+ y1_predict_btn_xgb = gr.Button(value="Predict (XGBoost)")
937
+ y1_predict_btn_lgb = gr.Button(value="Predict (LightGBM)")
938
+ y1_predict_btn_cb = gr.Button(value="Predict (CatBoost)")
939
+ y1_predict_btn_rf = gr.Button(value="Predict (Random Forest)")
940
+ label = gr.Label()
941
+
942
+ with gr.Row():
943
+ y1_interpret_btn_xgb = gr.Button(value="Explain (XGBoost)")
944
+ y1_interpret_btn_lgb = gr.Button(value="Explain (LightGBM)")
945
+ y1_interpret_btn_cb = gr.Button(value="Explain (CatBoost)")
946
+ y1_interpret_btn_rf = gr.Button(value="Explain (Random Forest)")
947
+
948
+ plot = gr.Plot()
949
+
950
+ y1_predict_btn_xgb.click(
951
+ y1_predict_xgb,
952
+ inputs = inputs,
953
+ outputs = [label]
954
+ )
955
+
956
+ y1_predict_btn_lgb.click(
957
+ y1_predict_lgb,
958
+ inputs = inputs,
959
+ outputs = [label]
960
+ )
961
+
962
+ y1_predict_btn_cb.click(
963
+ y1_predict_cb,
964
+ inputs = inputs,
965
+ outputs = [label]
966
+ )
967
+
968
+ y1_predict_btn_rf.click(
969
+ y1_predict_rf,
970
+ inputs = inputs,
971
+ outputs = [label]
972
+ )
973
+
974
+ y1_interpret_btn_xgb.click(
975
+ y1_interpret_xgb,
976
+ inputs = inputs,
977
+ outputs = [plot],
978
+ )
979
+
980
+ y1_interpret_btn_lgb.click(
981
+ y1_interpret_lgb,
982
+ inputs = inputs,
983
+ outputs = [plot],
984
+ )
985
+
986
+ y1_interpret_btn_cb.click(
987
+ y1_interpret_cb,
988
+ inputs = inputs,
989
+ outputs = [plot],
990
+ )
991
+
992
+ y1_interpret_btn_rf.click(
993
+ y1_interpret_rf,
994
+ inputs = inputs,
995
+ outputs = [plot],
996
+ )
997
+
998
+ demo.launch()