mertkarabacak
commited on
Commit
•
f3a1bf5
1
Parent(s):
8e4e412
Upload app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,7 @@ import gradio as gr
|
|
25 |
import random
|
26 |
import re
|
27 |
|
|
|
28 |
#Read data.
|
29 |
from datasets import load_dataset
|
30 |
x1 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="mortality_data.csv", use_auth_token = HF_TOKEN)
|
@@ -32,6 +33,7 @@ x1 = pd.DataFrame(x1['train'])
|
|
32 |
variables = ['Age', 'Sex', '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', 'Total_GCS', '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', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', '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', '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__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Cerebral_Monitoring', 'Protective_Device', 'OUTCOME']
|
33 |
x1 = x1[variables]
|
34 |
|
|
|
35 |
#Assign unique values as answer options.
|
36 |
unique_SEX = ['Male', 'Female', 'Unknown']
|
37 |
unique_RACE = ['White', 'Black', 'Asian', 'American Indian', 'Pacific Islander', 'Other', 'Unknown']
|
@@ -93,6 +95,7 @@ unique_HOSPITALTYPE = ['Non-profit', 'For profit', 'Government', 'Unknown']
|
|
93 |
unique_BEDSIZE = ['More than 600', '401 to 600', '201 to 400', '200 or fewer']
|
94 |
unique_PRIMARYMETHODPAYMENT = ['Private/commercial insurance', 'Medicaid', 'Medicare', 'Other government', 'Self-pay', 'Other', 'Not billed', 'Unknown']
|
95 |
|
|
|
96 |
#Prepare data for the outcome 1 (mortality).
|
97 |
y1 = x1.pop('OUTCOME')
|
98 |
resampler = SMOTE(random_state = 0)
|
@@ -112,11 +115,13 @@ for col in categorical_columns1:
|
|
112 |
d1 = dict.fromkeys(x1_rf.select_dtypes(np.int64).columns, str)
|
113 |
x1_rf = x1_rf.astype(d1)
|
114 |
|
|
|
115 |
#Assign hyperparameters.
|
116 |
-
y1_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda':
|
117 |
-
y1_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.
|
118 |
-
y1_cb_params = {'objective': '
|
119 |
-
y1_rf_params = {'criterion': '
|
|
|
120 |
|
121 |
#Modeling for y1 (mortality).
|
122 |
y1_model_xgb = xgb.train(params=y1_xgb_params, dtrain=y1_data_xgb)
|
@@ -133,6 +138,7 @@ y1_rf = rf(**y1_rf_params)
|
|
133 |
y1_model_rf = y1_rf.fit(x1_rf, y1)
|
134 |
y1_explainer_rf = shap.TreeExplainer(y1_model_rf)
|
135 |
|
|
|
136 |
#Define predict for y1 (mortality).
|
137 |
def y1_predict_xgb(*args):
|
138 |
df_xgb = pd.DataFrame([args], columns=x1.columns)
|
@@ -222,6 +228,7 @@ def y1_interpret_rf(*args):
|
|
222 |
plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
|
223 |
return fig_m
|
224 |
|
|
|
225 |
with gr.Blocks(title = "NTDB-Epidural") as demo:
|
226 |
|
227 |
gr.Markdown(
|
|
|
25 |
import random
|
26 |
import re
|
27 |
|
28 |
+
|
29 |
#Read data.
|
30 |
from datasets import load_dataset
|
31 |
x1 = load_dataset("mertkarabacak/NTDB-Epidural", data_files="mortality_data.csv", use_auth_token = HF_TOKEN)
|
|
|
33 |
variables = ['Age', 'Sex', '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', 'Total_GCS', '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', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', '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', '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__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Cerebral_Monitoring', 'Protective_Device', 'OUTCOME']
|
34 |
x1 = x1[variables]
|
35 |
|
36 |
+
|
37 |
#Assign unique values as answer options.
|
38 |
unique_SEX = ['Male', 'Female', 'Unknown']
|
39 |
unique_RACE = ['White', 'Black', 'Asian', 'American Indian', 'Pacific Islander', 'Other', 'Unknown']
|
|
|
95 |
unique_BEDSIZE = ['More than 600', '401 to 600', '201 to 400', '200 or fewer']
|
96 |
unique_PRIMARYMETHODPAYMENT = ['Private/commercial insurance', 'Medicaid', 'Medicare', 'Other government', 'Self-pay', 'Other', 'Not billed', 'Unknown']
|
97 |
|
98 |
+
|
99 |
#Prepare data for the outcome 1 (mortality).
|
100 |
y1 = x1.pop('OUTCOME')
|
101 |
resampler = SMOTE(random_state = 0)
|
|
|
115 |
d1 = dict.fromkeys(x1_rf.select_dtypes(np.int64).columns, str)
|
116 |
x1_rf = x1_rf.astype(d1)
|
117 |
|
118 |
+
|
119 |
#Assign hyperparameters.
|
120 |
+
y1_xgb_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 3.540855010579091e-08, 'alpha': 4.005546508605542e-08, 'max_depth': 5, 'eta': 5.190362998186933e-08, 'gamma': 1.1458984717217304e-05, 'grow_policy': 'depthwise'}
|
121 |
+
y1_lgb_params = {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.5873889067286373, 'lambda_l2': 0.0043364331356120405, 'num_leaves': 221, 'feature_fraction': 0.8036023624154648, 'bagging_fraction': 0.43028542431491096, 'bagging_freq': 5, 'min_child_samples': 7}
|
122 |
+
y1_cb_params = {'objective': 'Logloss', 'colsample_bylevel': 0.02893626365611705, 'depth': 9, 'boosting_type': 'Plain', 'bootstrap_type': 'Bayesian', 'bagging_temperature': 0.8396785798333539}
|
123 |
+
y1_rf_params = {'criterion': 'entropy', 'max_features': None, 'max_depth': 71, 'n_estimators': 900, 'min_samples_leaf': 4, 'min_samples_split': 5}
|
124 |
+
|
125 |
|
126 |
#Modeling for y1 (mortality).
|
127 |
y1_model_xgb = xgb.train(params=y1_xgb_params, dtrain=y1_data_xgb)
|
|
|
138 |
y1_model_rf = y1_rf.fit(x1_rf, y1)
|
139 |
y1_explainer_rf = shap.TreeExplainer(y1_model_rf)
|
140 |
|
141 |
+
|
142 |
#Define predict for y1 (mortality).
|
143 |
def y1_predict_xgb(*args):
|
144 |
df_xgb = pd.DataFrame([args], columns=x1.columns)
|
|
|
228 |
plt.ylabel("Feature", fontsize = 16, labelpad=14, fontweight = 'bold')
|
229 |
return fig_m
|
230 |
|
231 |
+
|
232 |
with gr.Blocks(title = "NTDB-Epidural") as demo:
|
233 |
|
234 |
gr.Markdown(
|