Yadvendra commited on
Commit
d9f9507
·
verified ·
1 Parent(s): 5cc8ee4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pickle
4
+ from sklearn.preprocessing import StandardScaler
5
+ from sklearn.linear_model import LogisticRegression
6
+
7
+ # Load the trained model and scaler
8
+ model = pickle.load(open('heart_failure_prediction.pkl', 'rb')) # Load the logistic regression model
9
+ scaler = pickle.load(open('scaler.pkl', 'rb')) # Load the scaler
10
+
11
+ #streamlit page
12
+ st.title('Heart Failure Prediction')
13
+ st.header('Enter the following details to predict heart failure:')
14
+ age = st.number_input('Age', min_value=0, max_value=120, value=25)
15
+ anaemia = st.selectbox('Anaemia', [0, 1])
16
+ creatinine_phosphokinase = st.number_input('Creatinine Phosphokinase', min_value=0, max_value=10000, value=100)
17
+ diabetes = st.selectbox('Diabetes', [0, 1])
18
+ ejection_fraction = st.number_input('Ejection Fraction', min_value=0, max_value=100, value=50)
19
+ high_blood_pressure = st.selectbox('High Blood Pressure', [0, 1])
20
+ platelets = st.number_input('Platelets', min_value=0, max_value=1000000, value=10000)
21
+ serum_creatinine = st.number_input('Serum Creatinine', min_value=0.0, max_value=10.0, value=1.0)
22
+ serum_sodium = st.number_input('Serum Sodium', min_value=0, max_value=200, value=100)
23
+ sex = st.selectbox('Sex', ('Male', 'Female'))
24
+
25
+ # Map 'Male' to 1 and 'Female' to 0
26
+ if sex == 'Male':
27
+ sex_value = 1
28
+ else:
29
+ sex_value = 0
30
+
31
+ smoking = st.selectbox('Smoking', [0, 1])
32
+ time = st.number_input('Time', min_value=0, max_value=1000, value=100)
33
+
34
+ input_data = np.array([[age, anaemia, creatinine_phosphokinase, diabetes, ejection_fraction, high_blood_pressure, platelets, serum_creatinine, serum_sodium, sex_value, smoking, time]])
35
+
36
+ if st.button('Predict'):
37
+ scaled_input = scaler.transform(input_data)
38
+ prediction = model.predict(scaled_input)
39
+ if prediction[0] == 0:
40
+ st.write('The person is not at risk of heart failure.')
41
+ else:
42
+ st.write('The person is at risk of heart failure.')
43
+