gdntmbnn commited on
Commit
4aedbfd
1 Parent(s): 350a6d5

Upload 7 files

Browse files
Files changed (7) hide show
  1. app.py +75 -0
  2. boxcox.pkl +3 -0
  3. list_cat_col.txt +1 -0
  4. list_num_col.txt +1 -0
  5. model_scaler.pkl +3 -0
  6. requirements.txt +5 -0
  7. rf_best_model.pkl +3 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import joblib
5
+ import ast
6
+
7
+ # Set page title and favicon
8
+ st.set_page_config(page_title='Heart Failure Prediction', page_icon=':heart:')
9
+
10
+ # Load models and data
11
+ with open('model_scaler.pkl', 'rb') as file_1:
12
+ model_scaler = joblib.load(file_1)
13
+
14
+ with open('rf_best_model.pkl', 'rb') as file_2:
15
+ rf_random_best = joblib.load(file_2)
16
+
17
+ with open('list_num_col.txt', 'r') as file_3:
18
+ num_col = file_3.read()
19
+
20
+ with open('list_cat_col.txt', 'r') as file_4:
21
+ cat_col = file_4.read()
22
+
23
+ with open('boxcox.pkl', 'rb') as file_5:
24
+ box = joblib.load(file_5)
25
+
26
+ num_col = ast.literal_eval(num_col)
27
+ cat_col = ast.literal_eval(cat_col)
28
+
29
+ # Set page header
30
+ st.title('Heart Failure Prediction')
31
+
32
+ # Add page description
33
+ st.markdown('This web app predicts the likelihood of heart failure based on several factors. Fill in the form below and click the "Predict" button to get your results.')
34
+
35
+ # Add form inputs
36
+ time = st.slider('Follow-up period (days)', min_value=1, max_value=365, step=1)
37
+ age = st.slider('Age', 30, 120, step=1)
38
+ ejection_fraction = st.number_input('Ejection fraction', min_value=1, max_value=100, step=1)
39
+ serum_creatinine = st.number_input('Serum creatinine', min_value=0.0, max_value=10.0, step=0.01)
40
+ serum_sodium = st.number_input('Serum sodium', min_value=100, max_value=150, step=1)
41
+ anaemia = st.radio('Anemia', ('Yes', 'No'))
42
+ diabetes = st.radio('Diabetes', ('Yes', 'No'))
43
+ smoking = st.radio('Smoking', ('Yes', 'No'))
44
+
45
+ # Add prediction button
46
+ if st.button('Predict'):
47
+ # Process form inputs
48
+ data_inf = pd.DataFrame({'time': time,
49
+ 'ejection_fraction': ejection_fraction,
50
+ 'age': age,
51
+ 'serum_creatinine': serum_creatinine,
52
+ 'serum_sodium': serum_sodium,
53
+ 'anaemia': 1 if anaemia == 'Yes' else 0,
54
+ 'diabetes': 1 if diabetes == 'Yes' else 0,
55
+ 'smoking': 1 if smoking == 'Yes' else 0
56
+ }, index=[0])
57
+
58
+ data_inf_t = box.transform(data_inf)
59
+ data_inf_num = data_inf_t[num_col]
60
+ data_inf_cat = data_inf_t[cat_col]
61
+
62
+ data_inf_num_scaled = data_inf_num.copy()
63
+ data_inf_num_scaled[num_col] = model_scaler.transform(data_inf_num[num_col])
64
+ data_inf_cat_encoded = data_inf_cat.copy()
65
+
66
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
67
+
68
+ result = rf_random_best.predict(data_inf_final)[0]
69
+
70
+ # Display prediction result
71
+ st.markdown('## Prediction result')
72
+ if result == 1:
73
+ st.markdown(':heart: **High risk of heart failure!** :heart:')
74
+ else:
75
+ st.markdown(':thumbsup: **Low risk of heart failure.** :thumbsup:')
boxcox.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28ee56a50a1c2e09651cb183c69b021af913aba505784c6d89e57a19ea8ad14a
3
+ size 474
list_cat_col.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ['anaemia', 'diabetes', 'smoking']
list_num_col.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ['age', 'ejection_fraction', 'serum_creatinine', 'serum_sodium', 'time']
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9dc460a36f578c03d24eaaab347fc54ad89ba41ff63175f6b4316d5b5b709748
3
+ size 723
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ joblib
3
+ scikit-learn
4
+ pandas
5
+ matplotlib
rf_best_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:595d9f36c1f14f41bffac6bd0e4c9fe807df305f43fd218b964020aaf6babb36
3
+ size 400462