Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- feature_columns.pkl +3 -0
- hospital_readmissions.csv +0 -0
- label_encoders.pkl +3 -0
- label_encoders_2.pkl +3 -0
- lgbm_model.pkl +3 -0
- rf_tuned_model.pkl +3 -0
- web.py +83 -0
- xgb_model.pkl +3 -0
feature_columns.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:420aef88aed5ca5dddb4cba12386095b1a01c790a956e08f2df64627f0987830
|
3 |
+
size 425
|
hospital_readmissions.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
label_encoders.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bd4171507eeb3a2a2a03232dd78213690254c02f629501e3dae519367c430a7e
|
3 |
+
size 2074
|
label_encoders_2.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9f3a92a7bdd1f3c46683a18dab5bad15045ae1168fd8ae697a26c74d0278886d
|
3 |
+
size 1851
|
lgbm_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:71f2545e6a4b6f652c0141ca199fb5971c6c0babb30ddc9286b1e79b30627d75
|
3 |
+
size 681956
|
rf_tuned_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ad7fcd8e2055b459da82bf58ce958877d4c03ad382545103909cb97b4d57a7db
|
3 |
+
size 11916921
|
web.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import joblib
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load trained models
|
7 |
+
rf_model = joblib.load("rf_tuned_model.pkl")
|
8 |
+
xgb_model = joblib.load("xgb_model.pkl")
|
9 |
+
lgbm_model = joblib.load("lgbm_model.pkl")
|
10 |
+
|
11 |
+
# Load encoders and feature order
|
12 |
+
label_encoders = joblib.load("label_encoders.pkl")
|
13 |
+
label_encoders_2 = joblib.load("label_encoders_2.pkl")
|
14 |
+
feature_order = joblib.load("feature_columns.pkl")
|
15 |
+
|
16 |
+
st.title("🏥 Hospital Readmission Prediction App")
|
17 |
+
|
18 |
+
st.sidebar.header("📋 Enter Patient Information")
|
19 |
+
|
20 |
+
# User input fields
|
21 |
+
time_in_hospital = st.sidebar.number_input("Days in Hospital", min_value=1, max_value=30, step=1)
|
22 |
+
n_lab_procedures = st.sidebar.number_input("Number of Lab Procedures", min_value=0, max_value=100, step=1)
|
23 |
+
n_procedures = st.sidebar.number_input("Number of Procedures", min_value=0, max_value=10, step=1)
|
24 |
+
n_medications = st.sidebar.number_input("Number of Medications", min_value=0, max_value=50, step=1)
|
25 |
+
age = st.sidebar.selectbox("Age Group", ["[0-10)", "[10-20)", "[20-30)", "[30-40)", "[40-50)", "[50-60)", "[60-70)", "[70-80)", "[80-90)", "[90-100)"])
|
26 |
+
glucose_test = st.sidebar.selectbox("Glucose Test", ["Yes", "No"])
|
27 |
+
A1Ctest = st.sidebar.selectbox("A1C Test", ["Yes", "No"])
|
28 |
+
change = st.sidebar.selectbox("Change in Medication", ["Yes", "No"])
|
29 |
+
diabetes_med = st.sidebar.selectbox("Diabetes Medication", ["Yes", "No"])
|
30 |
+
|
31 |
+
# Convert user input into a DataFrame
|
32 |
+
user_input_df = pd.DataFrame({
|
33 |
+
"time_in_hospital": [time_in_hospital],
|
34 |
+
"n_lab_procedures": [n_lab_procedures],
|
35 |
+
"n_procedures": [n_procedures],
|
36 |
+
"n_medications": [n_medications],
|
37 |
+
"age": [age],
|
38 |
+
"glucose_test": [glucose_test],
|
39 |
+
"A1Ctest": [A1Ctest],
|
40 |
+
"change": [change],
|
41 |
+
"diabetes_med": [diabetes_med]
|
42 |
+
})
|
43 |
+
|
44 |
+
# Encode categorical features
|
45 |
+
for col in label_encoders:
|
46 |
+
if col in user_input_df:
|
47 |
+
user_input_df[col] = user_input_df[col].apply(lambda x: x if x in label_encoders[col].classes_ else "Unknown")
|
48 |
+
label_encoders[col].classes_ = np.append(label_encoders[col].classes_, "Unknown")
|
49 |
+
user_input_df[col] = label_encoders[col].transform(user_input_df[col])
|
50 |
+
|
51 |
+
# Ensure the feature order matches the training data
|
52 |
+
user_input_df = user_input_df.reindex(columns=feature_order, fill_value=0)
|
53 |
+
|
54 |
+
# Predict using the models
|
55 |
+
if st.sidebar.button("🔍 Predict Readmission"):
|
56 |
+
rf_prediction = rf_model.predict(user_input_df)[0]
|
57 |
+
rf_proba = rf_model.predict_proba(user_input_df)[0][1]
|
58 |
+
|
59 |
+
xgb_prediction = xgb_model.predict(user_input_df)[0]
|
60 |
+
xgb_proba = xgb_model.predict_proba(user_input_df)[0][1]
|
61 |
+
|
62 |
+
lgbm_prediction = lgbm_model.predict(user_input_df)[0]
|
63 |
+
lgbm_proba = lgbm_model.predict_proba(user_input_df)[0][1]
|
64 |
+
|
65 |
+
# Display Results
|
66 |
+
st.subheader("📊 Prediction Results")
|
67 |
+
|
68 |
+
def format_prediction(pred, proba):
|
69 |
+
if pred == 0:
|
70 |
+
return f"🔴 **Likely to be Readmitted** (Probability: {proba:.2%})"
|
71 |
+
else:
|
72 |
+
return f"🟢 **Not Likely to be Readmitted** (Probability: {proba:.2%})"
|
73 |
+
|
74 |
+
st.write("**Random Forest:**", format_prediction(rf_prediction, rf_proba))
|
75 |
+
st.write("**XGBoost:**", format_prediction(xgb_prediction, xgb_proba))
|
76 |
+
st.write("**LightGBM:**", format_prediction(lgbm_prediction, lgbm_proba))
|
77 |
+
|
78 |
+
# Choose final prediction (majority vote)
|
79 |
+
final_prediction = round((rf_prediction + xgb_prediction + lgbm_prediction) / 3)
|
80 |
+
final_proba = (rf_proba + xgb_proba + lgbm_proba) / 3
|
81 |
+
|
82 |
+
st.markdown("### 🏥 **Final Prediction:**")
|
83 |
+
st.write(format_prediction(final_prediction, final_proba))
|
xgb_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eba428f342bfd9bd713c84d2cd3b2fd12d7fca47810eec2acb6692282480f759
|
3 |
+
size 3404829
|