Spaces:
Runtime error
Runtime error
Upload 6 files
Browse files- app.py +64 -0
- boxcox.pkl +3 -0
- list_cat_col.txt +1 -0
- list_num_col.txt +1 -0
- model_scaler.pkl +3 -0
- rf_best_model.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import joblib
|
5 |
+
import ast
|
6 |
+
|
7 |
+
st.title('Heart Failure Prediction')
|
8 |
+
|
9 |
+
with open('model_scaler.pkl', 'rb') as file_1:
|
10 |
+
model_scaler = joblib.load(file_1)
|
11 |
+
|
12 |
+
with open('rf_best_model.pkl', 'rb') as file_2:
|
13 |
+
rf_random_best = joblib.load(file_2)
|
14 |
+
|
15 |
+
with open('list_num_col.txt', 'r') as file_3:
|
16 |
+
num_col = file_3.read()
|
17 |
+
|
18 |
+
with open('list_cat_col.txt', 'r') as file_4:
|
19 |
+
cat_col = file_4.read()
|
20 |
+
|
21 |
+
with open('boxcox.pkl', 'rb') as file_5:
|
22 |
+
box = joblib.load(file_5)
|
23 |
+
|
24 |
+
num_col = ast.literal_eval(num_col)
|
25 |
+
cat_col = ast.literal_eval(cat_col)
|
26 |
+
|
27 |
+
|
28 |
+
# time, ejection_fraction, age, serum creatinine, serum_sodium, creatinine_phosphokinase, diabetes, high_blood_pressure, smoking
|
29 |
+
|
30 |
+
time = st.slider('Follow up perriod (days) : ',min_value=1,max_value=365,step=1)
|
31 |
+
age = st.slider('Age : ', 30,120,step=1)
|
32 |
+
ejection_fraction = st.number_input('Ejection Fraction : ',min_value=1,max_value=100,step=1)
|
33 |
+
serum_creatinine = st.number_input('Serum Creatinine : ',min_value=0.0,max_value=10.0,step=0.01)
|
34 |
+
serum_sodium = st.number_input('Serum Sodium : ',min_value=100,max_value=150,step=1)
|
35 |
+
anaemia = st.radio('Anemia (1=Yes, 0=NO) : ',(1, 0))
|
36 |
+
diabetes = st.radio('Diabetes (1=Yes, 0=NO) : ',(1, 0))
|
37 |
+
smoking = st.radio('Smoking (1=Yes, 0=NO) : ',(1, 0))
|
38 |
+
|
39 |
+
if st.button('Predict'):
|
40 |
+
|
41 |
+
data_inf = pd.DataFrame({'time':time,
|
42 |
+
'ejection_fraction':ejection_fraction,
|
43 |
+
'age':age,
|
44 |
+
'serum_creatinine':serum_creatinine,
|
45 |
+
'serum_sodium':serum_sodium,
|
46 |
+
'anaemia':anaemia,
|
47 |
+
'diabetes':diabetes,
|
48 |
+
'smoking':smoking
|
49 |
+
},index=[0])
|
50 |
+
|
51 |
+
data_inf_t = box.transform(data_inf)
|
52 |
+
data_inf_num = data_inf_t[num_col]
|
53 |
+
data_inf_cat = data_inf_t[cat_col]
|
54 |
+
|
55 |
+
data_inf_num_scaled = data_inf_num.copy()
|
56 |
+
data_inf_num_scaled[num_col] = model_scaler.transform(data_inf_num[num_col])
|
57 |
+
data_inf_cat_encoded = data_inf_cat.copy()
|
58 |
+
data_inf_num_scaled
|
59 |
+
|
60 |
+
data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
|
61 |
+
|
62 |
+
result = rf_random_best.predict(data_inf_final)[0]
|
63 |
+
st.write('Predicted Result:')
|
64 |
+
st.header(result)
|
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
|
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
|