Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,12 @@ import gradio as gr
|
|
2 |
import xgboost
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
|
|
|
|
5 |
|
6 |
|
7 |
def predicter(SpO2, Age, Weight, Height, Temperature, Gender, Race):
|
|
|
8 |
xgb_reg = xgboost.XGBClassifier(tree_method = 'approx',
|
9 |
enable_categorical = True,
|
10 |
learning_rate=.1,
|
@@ -12,9 +15,19 @@ def predicter(SpO2, Age, Weight, Height, Temperature, Gender, Race):
|
|
12 |
n_estimators=70,
|
13 |
early_stopping_rounds = 0,
|
14 |
scale_pos_weight=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
|
|
16 |
xgb_reg.load_model('classifier_fewer_features_HH.json')
|
17 |
-
|
|
|
18 |
if Gender == "Male":
|
19 |
gen = "M"
|
20 |
elif Gender == "Female":
|
@@ -22,13 +35,19 @@ def predicter(SpO2, Age, Weight, Height, Temperature, Gender, Race):
|
|
22 |
|
23 |
cont_features = ['SpO2','anchor_age','weight','height','temperature']
|
24 |
cat_features = ['gender','race_group']
|
25 |
-
|
26 |
user_input = pd.DataFrame([[SpO2/100,Age/91,Weight/309,Height/213,Temperature/42.06,gen,Race]],columns = cont_features+cat_features)
|
27 |
user_input[cat_features] = user_input[cat_features].copy().astype('category')
|
28 |
-
pred = xgb_reg.predict_proba(user_input)
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
demo = gr.Interface(
|
|
|
2 |
import xgboost
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
5 |
+
import json
|
6 |
+
import pickle
|
7 |
|
8 |
|
9 |
def predicter(SpO2, Age, Weight, Height, Temperature, Gender, Race):
|
10 |
+
'''
|
11 |
xgb_reg = xgboost.XGBClassifier(tree_method = 'approx',
|
12 |
enable_categorical = True,
|
13 |
learning_rate=.1,
|
|
|
15 |
n_estimators=70,
|
16 |
early_stopping_rounds = 0,
|
17 |
scale_pos_weight=1)
|
18 |
+
'''
|
19 |
+
with open('HH_ensemble_classifier_online.json', 'r') as file:
|
20 |
+
model_data = json.load(file)
|
21 |
+
for item in model_data:
|
22 |
+
index = item['index']
|
23 |
+
model = pickle.loads(item['model'].encode('latin1'))
|
24 |
+
loaded_models.append(model)
|
25 |
|
26 |
+
classifier_list = loaded_models
|
27 |
+
'''
|
28 |
xgb_reg.load_model('classifier_fewer_features_HH.json')
|
29 |
+
'''
|
30 |
+
|
31 |
if Gender == "Male":
|
32 |
gen = "M"
|
33 |
elif Gender == "Female":
|
|
|
35 |
|
36 |
cont_features = ['SpO2','anchor_age','weight','height','temperature']
|
37 |
cat_features = ['gender','race_group']
|
38 |
+
|
39 |
user_input = pd.DataFrame([[SpO2/100,Age/91,Weight/309,Height/213,Temperature/42.06,gen,Race]],columns = cont_features+cat_features)
|
40 |
user_input[cat_features] = user_input[cat_features].copy().astype('category')
|
|
|
41 |
|
42 |
+
|
43 |
+
predictions = np.zeros((len(classifier_list),2))
|
44 |
+
for i in range(len(classifier_list)):
|
45 |
+
predictions[i] = classifier_list[i].predict_proba(user_input[cont_features + cat_features])
|
46 |
+
averaged_prediction = predictions.mean(axis=0)
|
47 |
+
'''
|
48 |
+
pred = xgb_reg.predict_proba(user_input)
|
49 |
+
'''
|
50 |
+
return {"No Hidden Hypoxemia": float(averaged_prediction[0]), "Hidden Hypoxemia": float(averaged_prediction[1])}
|
51 |
|
52 |
|
53 |
demo = gr.Interface(
|