Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
import streamlit as st
|
| 6 |
+
import pickle
|
| 7 |
+
|
| 8 |
+
from scipy import stats
|
| 9 |
+
from sklearn.impute import KNNImputer
|
| 10 |
+
from scipy.stats import chi2_contingency
|
| 11 |
+
from sklearn.model_selection import train_test_split, cross_validate,StratifiedKFold
|
| 12 |
+
from imblearn.over_sampling import SMOTE
|
| 13 |
+
import optuna
|
| 14 |
+
from sklearn.preprocessing import StandardScaler, OneHotEncoder, OrdinalEncoder
|
| 15 |
+
from sklearn.pipeline import Pipeline
|
| 16 |
+
from sklearn.compose import ColumnTransformer
|
| 17 |
+
from imblearn.pipeline import Pipeline as ImbPipeline
|
| 18 |
+
from optuna.samplers import TPESampler
|
| 19 |
+
from optuna.visualization import plot_param_importances,plot_optimization_history
|
| 20 |
+
|
| 21 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 22 |
+
|
| 23 |
+
st.title("10-Year CHD Risk Prediction")
|
| 24 |
+
|
| 25 |
+
# Take Inputs
|
| 26 |
+
|
| 27 |
+
with st.expander("Basic Details"):
|
| 28 |
+
age = st.number_input("Age", 1, 120, 30)
|
| 29 |
+
education = st.selectbox("Education Level", [1, 2, 3, 4])
|
| 30 |
+
|
| 31 |
+
with st.expander("Medical History"):
|
| 32 |
+
sex = st.radio("Sex", ["Male", "Female"])
|
| 33 |
+
is_smoking = st.radio("Do you smoke?", ["Yes", "No"])
|
| 34 |
+
cigs_per_day = st.slider("Cigarettes Per Day", 0, 100, 0)
|
| 35 |
+
bp_meds = st.radio("Taking Blood Pressure Medication?", ["Yes", "No"])
|
| 36 |
+
prevalent_stroke = st.radio("Had a stroke?", ["Yes", "No"])
|
| 37 |
+
prevalent_hyp = st.radio("Hypertension?", ["Yes", "No"])
|
| 38 |
+
diabetes = st.radio("Diabetes?", ["Yes", "No"])
|
| 39 |
+
|
| 40 |
+
with st.expander("Health Measurements"):
|
| 41 |
+
total_cholesterol = st.number_input("Total Cholesterol", 100.0, 400.0, 200.0)
|
| 42 |
+
systolic_bp = st.slider("Systolic BP", 50.0, 250.0, 120.0)
|
| 43 |
+
diastolic_bp = st.slider("Diastolic BP", 30.0, 150.0, 80.0)
|
| 44 |
+
bmi = st.number_input("BMI", 10.0, 50.0, 25.0)
|
| 45 |
+
heart_rate = st.slider("Heart Rate", 30.0, 200.0, 70.0)
|
| 46 |
+
glucose = st.number_input("Glucose", 50.0, 300.0, 90.0)
|
| 47 |
+
|
| 48 |
+
model = pickle.load(open("final_pipeline.pkl","rb"))
|
| 49 |
+
|
| 50 |
+
if st.button("Predict"):
|
| 51 |
+
prediction = model.predict([[age, education, sex, is_smoking, cigs_per_day, bp_meds, prevalent_stroke,
|
| 52 |
+
prevalent_hyp, diabetes, total_cholesterol, systolic_bp, diastolic_bp,
|
| 53 |
+
bmi, heart_rate, glucose]])
|
| 54 |
+
|
| 55 |
+
result = prediction[0]
|
| 56 |
+
st.write(f"**Predicted Value:** {result}")
|
| 57 |
+
|
| 58 |
+
if result == 1:
|
| 59 |
+
st.error("⚠️ High Risk: You have a higher chance of developing Coronary Heart Disease (CHD) in the next 10 years. Please consult a doctor and consider lifestyle changes.")
|
| 60 |
+
else:
|
| 61 |
+
st.success("✅ Low Risk: Your predicted risk of developing CHD in the next 10 years is low. Keep maintaining a healthy lifestyle!")
|