Minerva143 commited on
Commit
3e2d3d3
1 Parent(s): a16c233

First commit. Files added

Browse files
Arch_Test_UserData.png ADDED
Test_diag_v2.png ADDED
Train_diag.png ADDED
app.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import altair as alt
4
+ import numpy as np
5
+ from PIL import Image
6
+ import pickle
7
+
8
+ with open('best_model_hypertension.pkl', 'rb') as file:
9
+ hypertension_model = pickle.load(file)
10
+
11
+ with open('hypertension_scaler.pkl', 'rb') as file:
12
+ hypertension_scaler = pickle.load(file)
13
+
14
+ with open('best_model_stroke.pkl', 'rb') as file:
15
+ stroke_model = pickle.load(file)
16
+
17
+ with open('stroke_scaler.pkl', 'rb') as file:
18
+ stroke_scaler = pickle.load(file)
19
+
20
+ with open('best_model_diabetes.pkl', 'rb') as file:
21
+ diabetes_model = pickle.load(file)
22
+
23
+ with open('diabetes_scaler.pkl', 'rb') as file:
24
+ diabetes_scaler = pickle.load(file)
25
+
26
+ with open('best_model_heart.pkl', 'rb') as file:
27
+ heart_model = pickle.load(file)
28
+
29
+ with open('best_scaler_heart.pkl', 'rb') as file:
30
+ heart_scaler = pickle.load(file)
31
+
32
+ #Create header
33
+ st.write("""# Heart Attack Risk Predictor""")
34
+ st.write("""## How it works""")
35
+ st.write("view your predictions about your health condition based on your answers to the questions on the side panel.")
36
+
37
+ #image
38
+ st.write("""## Training Flow Diagram""")
39
+ image = Image.open('Train_diag.png')
40
+ st.image(image)
41
+
42
+ st.write("""## Prediction Flow Diagram""")
43
+ image = Image.open('Test_diag_v2.png')
44
+ st.image(image)
45
+
46
+
47
+ #links
48
+ st.write("""## Dataset links""")
49
+
50
+ st.write("https://www.kaggle.com/datasets/prosperchuks/health-dataset?select=diabetes_data.csv")
51
+ st.write("https://www.kaggle.com/datasets/iamsouravbanerjee/heart-attack-prediction-dataset")
52
+
53
+ # model types
54
+ st.write("""## Trained Model Types""")
55
+ st.write("Hypertension: ")
56
+ st.write("Stroke: ")
57
+ st.write("Diabetes: ")
58
+ st.write("Heart Attack: ")
59
+
60
+ #Bring in the data
61
+ data = pd.read_csv('heart_attack_prediction_dataset.csv')
62
+ st.write("## HEART ATTACK TRAIN DATA")
63
+ st.dataframe(data)
64
+
65
+ #Create and name sidebar
66
+ st.sidebar.header('Fill your survey')
67
+
68
+ st.sidebar.write("""#### Choose your values""")
69
+ def user_input_features():
70
+ age = st.sidebar.slider('Age', 18, 100, 25, 1)
71
+ sex = st.sidebar.slider('Sex (Male : 0, Female : 1)', 0, 1, 0, 1)
72
+ gen_health = st.sidebar.slider('General Health scale 1 = excellent ,2 = very good, 3 = good, 4 = fair, 5 = poor', 1, 5, 3, 1)
73
+ men_health = st.sidebar.slider('days of poor mental health scale 1-30 days', 0, 30, 0, 1)
74
+ cholesterol = st.sidebar.slider('Cholesterol level', 0, 600, 150, 5)
75
+ heart_rate = st.sidebar.slider('Heart Rate', 0, 160, 60, 1)
76
+ family_history = st.sidebar.slider('Family History(for heart attack). 0 = no,1 = yes', 0, 1, 0, 1)
77
+ obesity = st.sidebar.slider('Obesity. 0 = no,1 = yes', 0, 1, 0, 1)
78
+ alcohol_consumption = st.sidebar.slider('Alcohol Consumption(regularly).0 = no,1 = yes', 0, 1, 0, 1)
79
+ smoking_status = st.sidebar.slider('Smoking(regularly).0 = no,1 = yes', 0, 1, 0, 1)
80
+ exercise_hours = st.sidebar.slider('Exercise Hours Per Week', 0, 50, 15, 1)
81
+ stress_level = st.sidebar.slider('Stress Level', 0, 10, 3, 1)
82
+ sedentary_hours = st.sidebar.slider('Sedentary Hours Per Day', 0.0, 12.0, 6.0, 0.5)
83
+ income = st.sidebar.slider('Income', 0, 500000, 0, 1000)
84
+ education_level = st.sidebar.slider('Education level 1-10', 1, 10, 6, 1)
85
+ bmi = st.sidebar.slider('BMI', 0.0, 50.0, 20.0, 0.1)
86
+ triglycerides = st.sidebar.slider('Triglycerides Level', 0, 1000, 350, 10)
87
+ physical_days = st.sidebar.slider('Physical Activity Days Per Week', 0, 7, 3, 1)
88
+ sleep_hours = st.sidebar.slider('Sleep Hours Per Day', 0.0, 16.0, 8.0, 0.5)
89
+ systolic = st.sidebar.slider('Blood Pressure (Systolic)', 0, 200, 140, 1)
90
+ diastolic = st.sidebar.slider('Blood Pressure (Diastolic)', 0, 120, 80, 1)
91
+ diff_walk = st.sidebar.slider('Do you have serious difficulty walking or climbing stairs? 0 = no 1 = yes', 0, 1, 0, 1)
92
+ fruits = st.sidebar.slider('Consume Fruit 1 or more times per day. 0 = no,1 = yes', 0, 1, 0, 1)
93
+ veggies = st.sidebar.slider('Consume Vegetables 1 or more times per day. 0 = no ,1 = yes', 0, 1, 0, 1)
94
+ married = st.sidebar.slider('Ever Married. 0 = no,1 = yes', 0, 1, 0, 1)
95
+ work_type = st.sidebar.slider('patient job type: 0 - Never_worked, 1 - children, 2 - Govt_job, 3 - Self-employed, 4 - Private', 0, 4, 0, 1)
96
+ avg_glucose_level = st.sidebar.slider('Avg. glucose level', 0, 300, 100, 5)
97
+ cp = st.sidebar.slider('Chest pain type: 0: asymptomatic 1: typical angina 2: atypical angina 3: non-anginal pain', 0, 3, 0, 1)
98
+ trestbps = st.sidebar.slider('Resting blood pressure', 50, 250, 120, 1)
99
+ thalach = st.sidebar.slider('Maximum heart rate achieved', 50, 250, 120, 1)
100
+ exang = st.sidebar.slider('Exercise induced angina. 0 = no,1 = yes', 0, 1, 0, 1)
101
+ oldpeak = st.sidebar.slider('ST depression induced by exercise relative to rest.', 0.0, 10.0, 0.0, 0.1)
102
+ slope = st.sidebar.slider('The slope of the peak exercise ST segment: 0: upsloping 1: flat 2: downsloping', 0, 2, 2, 1)
103
+ ca = st.sidebar.slider('Number of major vessels (0–3) colored by flourosopy', 0, 5, 0, 1)
104
+ thal = st.sidebar.slider('3: Normal; 6: Fixed defect; 7: Reversable defect', 0, 10, 2, 1)
105
+
106
+ user_data_hypertension = {
107
+ 'cp' : cp,
108
+ 'trestbps' : trestbps,
109
+ 'chol' : cholesterol,
110
+ 'thalach' : thalach,
111
+ 'exang' : exang,
112
+ 'oldpeak' : oldpeak,
113
+ 'slope' : slope,
114
+ 'ca' : ca,
115
+ 'thal' : thal,
116
+ }
117
+
118
+ features_hypertension = pd.DataFrame(user_data_hypertension, index=[0])
119
+ features_hypertension_scaled = hypertension_scaler.transform(features_hypertension)
120
+ pred_hypertension = hypertension_model.predict(features_hypertension_scaled)
121
+
122
+ user_data_stroke = {
123
+ 'age' : age,
124
+ 'hypertension' : pred_hypertension[0],
125
+ 'heart_disease' : 0,
126
+ 'ever_married' : married,
127
+ 'work_type' : work_type,
128
+ 'avg_glucose_level' : avg_glucose_level,
129
+ 'bmi' : bmi,
130
+ 'smoking_status' : smoking_status
131
+ }
132
+
133
+ features_stroke = pd.DataFrame(user_data_stroke, index=[0])
134
+ features_stroke_scaled = stroke_scaler.transform(features_stroke)
135
+ pred_stroke = stroke_model.predict(features_stroke_scaled)
136
+
137
+ if physical_days > 2:
138
+ PhysHlth = 1
139
+ else:
140
+ PhysHlth = 0
141
+
142
+ if exercise_hours > 8:
143
+ PhysActivity = 1
144
+ else:
145
+ PhysActivity = 0
146
+
147
+ age_level = ((age -18) // 5 ) + 1
148
+ income_level = (income // 50000 ) + 1
149
+
150
+ user_data_diabetes = {
151
+ 'HighBP': pred_hypertension[0],
152
+ 'BMI': bmi,
153
+ 'Stroke': pred_stroke[0],
154
+ 'PhysActivity': PhysActivity,
155
+ 'Fruits': fruits,
156
+ 'Veggies': veggies,
157
+ 'HvyAlcoholConsump': alcohol_consumption,
158
+ 'GenHlth': gen_health,
159
+ 'MentHlth': men_health,
160
+ 'PhysHlth': PhysHlth,
161
+ 'DiffWalk': diff_walk,
162
+ 'Sex': 1 - sex,
163
+ 'Age': age_level,
164
+ 'Education': education_level,
165
+ 'Income': income_level
166
+ }
167
+
168
+ features_diabetes = pd.DataFrame(user_data_diabetes, index=[0])
169
+ features_diabetes_scaled = diabetes_scaler.transform(features_diabetes)
170
+ pred_diabetes = diabetes_model.predict(features_diabetes_scaled)
171
+
172
+ user_data_heart_attack ={
173
+ 'Age': age,
174
+ 'Cholesterol': cholesterol,
175
+ 'Heart Rate': heart_rate,
176
+ 'Diabetes': pred_diabetes[0],
177
+ 'Family History': family_history,
178
+ 'Obesity': obesity,
179
+ 'Alcohol Consumption': alcohol_consumption,
180
+ 'Exercise Hours Per Week' : exercise_hours,
181
+ 'Stress Level': stress_level,
182
+ 'Sedentary Hours Per Day': sedentary_hours,
183
+ 'Income': income,
184
+ 'BMI': bmi,
185
+ 'Triglycerides': triglycerides,
186
+ 'Physical Activity Days Per Week': physical_days,
187
+ 'Sleep Hours Per Day': sleep_hours,
188
+ 'BP_Systolic': systolic,
189
+ 'BP_Diastolic': diastolic,
190
+ 'Sex_Female': sex,
191
+ 'Sex_Male': 1 - sex,
192
+ }
193
+
194
+ features_heart_attack = pd.DataFrame(user_data_heart_attack, index=[0])
195
+ features_heart_attack_scaled = heart_scaler.transform(features_heart_attack)
196
+ pred_heart = heart_model.predict(features_heart_attack_scaled)
197
+
198
+ return features_stroke,pred_stroke, features_hypertension, pred_hypertension, features_diabetes, pred_diabetes, features_heart_attack, pred_heart
199
+
200
+ df_stroke, pred_stroke,df_hypertension, pred_hypertension,df_diabetes, pred_diabetes, df_heart_attack, pred_heart = user_input_features()
201
+
202
+
203
+
204
+ st.write("## YOUR PREDICTIONS: ")
205
+
206
+ st.write("## Hypertension User Input: ")
207
+ df_hypertension
208
+ st.write("Predicted Hypertension: ")
209
+ pred_hypertension
210
+ st.write("## Stroke User Input and Hypertension(pred. vals added): ")
211
+ df_stroke
212
+ st.write("Predicted Stroke: ")
213
+ pred_stroke
214
+ st.write("## Diabetes User Input and Hypertension and Stroke(pred. vals added): ")
215
+ df_diabetes
216
+ st.write("Predicted Diabetes: ")
217
+ pred_diabetes
218
+ st.write("## Heart Attack User Input and Diabetes: ")
219
+ df_heart_attack
220
+ st.write("Predicted Heart Attack: ")
221
+ pred_heart
222
+
223
+
224
+
225
+
best_model_diabetes.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb09ea1f5e97f6b3c261c242a8c01aae51afff3d9a84e81fff1f4afc540c75f6
3
+ size 564133
best_model_heart.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62ba22900ee91ff62878b441bcd30a600336247a685cd481d606a1185dd8d159
3
+ size 42962
best_model_hypertension.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4316f4bf985eb9e4d116ab34b0da8d914d0c511f1e056eb47019bd5babd0266c
3
+ size 9828
best_model_stroke.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b72e110aec7aaa86181885d32105cdcf3e6fc5cf6129f6bd295411333ca25b5
3
+ size 21252750
best_scaler_heart.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a75ff4113afd04e45b215f9410f7c2c01130408e5dc51d91d1401a3960dd537a
3
+ size 1292
diabetes_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25af59d1cc0b07383b0e61892b5343da0a52e263b86e12eb1c7c17acc865021f
3
+ size 1050
heart_attack_prediction_dataset.csv ADDED
The diff for this file is too large to render. See raw diff
 
hypertension_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21b155a0a1fafbd177e98d4d4aeabf4e4b2f82a0e684b099e41fe2e080b1119b
3
+ size 823
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit~=1.32.0
2
+ pandas~=2.0.3
3
+ altair~=5.0.1
4
+ numpy~=1.24.3
5
+ pillow~=10.3.0
6
+ scikit-learn==1.4.2
7
+ xgboost==2.0.3
stroke_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f3809aed07f1a21066d7599707894d216e11e69544c8002332a4ce42a2c56b4
3
+ size 835
test_diag.png ADDED