File size: 2,752 Bytes
c5fe76d
 
 
 
 
 
a754bc9
0cf2636
edd1f24
0cf2636
c5fe76d
0cf2636
 
c5fe76d
0cf2636
c5fe76d
 
99aee16
a754bc9
 
0cf2636
a754bc9
 
4a30a61
1b9943a
a754bc9
 
 
 
c5fe76d
 
0cf2636
c5fe76d
 
0cf2636
 
 
 
 
 
 
a754bc9
c5fe76d
0cf2636
 
c5fe76d
efec75f
3f75dad
c5fe76d
 
 
 
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
import joblib
import pandas as pd
import streamlit as st

model = joblib.load('model.joblib')
unique_values = joblib.load('unique_values.joblib')
    
unique_anaemia =  unique_values["anaemia"]
unique_diabetes =  unique_values["diabetes"]
unique_high_blood_pressure =  unique_values["high_blood_pressure"]
unique_sex =  unique_values["sex"]
unique_smoking =  unique_values["smoking"]

def main():
    st.title("Predict death rates from heart failure")

    with st.form("questionaire"):
        age = st.slider("Age", min_value=10, max_value=100)
        anaemia = st.selectbox("anaemia", options=unique_anaemia)
        creatinine_phosphokinase = st.slider("creatinine_phosphokinase (mcg/L)", min_value=10, max_value=120)
        diabetes = st.selectbox("diabetes", options=unique_diabetes)
        ejection_fraction = st.slider("ejection_fraction (percentage)", min_value=0, max_value=100)
        high_blood_pressure = st.selectbox("high_blood_pressure", options=unique_high_blood_pressure)
        platelets = st.slider("platelets (kiloplatelets/mL)", min_value=150000, max_value=300000)
        serum_creatinine = st.slider("serum_creatinine (mg/dL)", min_value=0.00, max_value=3.00)
        serum_sodium = st.slider("serum_sodium (mEq/L)", min_value=100, max_value=150)
        sex = st.selectbox("sex", options=unique_sex)
        smoking = st.selectbox("smoking", options=unique_smoking)
        time = st.slider("time: follow-up period (days)", min_value=0, max_value=300)

        # clicked==True only when the button is clicked
        clicked = st.form_submit_button("Predict death rates")
        if clicked:
            result=model.predict(pd.DataFrame({"age": [age],
                                               "anaemia": [anaemia],
                                               "creatinine_phosphokinase": [creatinine_phosphokinase],
                                               "diabetes": [diabetes],
                                               "ejection_fraction": [ejection_fraction],
                                               "high_blood_pressure": [high_blood_pressure],
                                               "platelets": [platelets],
                                               "serum_creatinine": [serum_creatinine],
                                               "serum_sodium": [serum_sodium],
                                               "sex": [sex],
                                               "smoking": [smoking],
                                               "time": [time]}))
            # Show prediction
            result = 'DEATH' if result[0] == 1 else 'NO DEATH'
            st.success("Your prediction death rates is "+result)

# Run main()
if __name__ == "__main__":
    main()