-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
109 lines (79 loc) · 2.99 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import streamlit as st
import numpy as np
import pandas as pd
import pickle
from sklearn.preprocessing import LabelEncoder
file_path = '/content/drive/MyDrive/CODING DOJO DS BOOTCAMP/PROJECTS/PROJECT 2/Stroke Prediction Dataset'
df = pd.read_csv('stroke-data.csv')
#load label encoder
le=LabelEncoder()
# Load our model
pickle_in = open('best_vc_ensemble.pkl', 'rb')
model = pickle.load(pickle_in)
def predict_stroke(gender, age, hypertension, heart_disease, ever_married,
work_type, Residence_type, avg_glucose_level, bmi,
smoking_status):
le=LabelEncoder()
le.fit(df['gender'].value_counts().index)
gender = le.transform([f'{gender}'])[0]
le.fit(df['ever_married'].value_counts().index)
ever_married = le.transform([f'{ever_married}'])[0]
le.fit(df['work_type'].value_counts().index)
work_type = le.transform([f'{work_type}'])[0]
le.fit(df['Residence_type'].value_counts().index)
Residence_type = le.transform([f'{Residence_type}'])[0]
le.fit(df['smoking_status'].value_counts().index)
smoking_status = le.transform([f'{smoking_status}'])[0]
prediction = model.predict([[gender, age, hypertension, heart_disease, ever_married,
work_type, Residence_type, avg_glucose_level, bmi,
smoking_status]])[0]
print(prediction)
if prediction == 0:
return "Negative, you don't have Heart Stroke. You are good to go"
elif prediction == 1:
return "Positive. You are most likely to have stroke. See a doctor NOW!"
def main():
st.title('Heart Stroke Prediction')
st.header('Fill in the below Features to determine wthether you have Stroke or not?')
left_column, right_column = st.columns(2)
with left_column:
gender = st.radio(
'Your gender?:',
np.unique(df['gender']))
age = st.number_input('Enter your Age?', value=0, step=1)
hypertension = st.radio(
'Have hypertension?:',
np.unique(['Yes', 'No']))
if hypertension == 'Yes':
hypertension = 1
elif hypertension == 'No':
hypertension = 0
heart_disease = st.radio(
'Have Heart Disease?:',
np.unique(['Yes', 'No']))
if heart_disease == 'Yes':
heart_disease = 1
elif heart_disease == 'No':
heart_disease = 0
ever_married = st.radio(
'Have you been ever married?:',
np.unique(df['ever_married']))
work_type = st.radio(
'Work Type?:',
np.unique(df['work_type']))
residence_type = st.radio(
'Residence Type?:',
np.unique(df['Residence_type']))
avg_glucose_level = st.slider('Average Glucose Level', 0.0, max(df["avg_glucose_level"]), 1.0)
bmi = st.slider('BMI', 0.0, max(df["bmi"]), 1.0)
smoking_status = st.radio(
'Smoking Status?:',
np.unique(df['smoking_status']))
result = ''
if st.button('Predict'):
result = predict_stroke(gender, age, hypertension, heart_disease, ever_married,
work_type, residence_type, avg_glucose_level, bmi,
smoking_status)
st.success(f'The output is: **{result}**')
if __name__ == '__main__':
main()