Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import pickle | |
| preproses = pickle.load(open("preproses.pkl", "rb")) | |
| # import model | |
| model = pickle.load(open("model.pkl", "rb")) | |
| #title | |
| st.title("Predict Death Event") | |
| st.write("Created by Sihar Pangaribuan") | |
| # User imput | |
| age = st.number_input(label='Age', min_value=40, max_value=95, value=40, step=1) | |
| anaemia = st.selectbox(label='Anemia', options=['0', '1']) | |
| creatinine_phosphokinase = st.number_input(label='Creatinine Phosphokinase', min_value=23, max_value=7861, value=23, step=1) | |
| diabetes = st.selectbox(label='Diabetes', options=['0', '1']) | |
| ejection_fraction = st.number_input(label='Ejection Fraction', min_value=14, max_value=80, value=14, step=1) | |
| high_blood_pressure = st.selectbox(label='High Blood Pressure', options=['0', '1']) | |
| platelets = st.number_input(label='Platelets', min_value=25100.0, max_value=850000.0, value=25100.0, step=1.0) | |
| serum_creatinine = st.number_input(label='Serum Creatinine', min_value=0.5, max_value=9.4, value=0.5, step=0.1) | |
| serum_sodium = st.number_input(label='Serum Sodium', min_value=133, max_value=148, value=133, step=1) | |
| sex = st.selectbox(label='Sex', options=['0', '1']) | |
| smoking = st.selectbox(label='Smoking', options=['0', '1']) | |
| time = st.number_input(label='Time', min_value=4, max_value=285, value=4, step=1) | |
| # Convert ke data frame | |
| data = pd.DataFrame({'age': [age], | |
| 'anemia': [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]}) | |
| data = preproses.transform(data) | |
| # model predict | |
| if st.button('Predict'): | |
| prediction = model.predict(data).tolist()[0] | |
| if prediction == 1: | |
| prediction = 'Death' | |
| else: | |
| prediction = 'Live' | |
| st.write('Based on user input, predicted: ') | |
| st.write(prediction) | |
| # interpretation | |
| # st.write('Predition Result: ') | |
| # if death == 0: | |
| # st.text('live') | |
| # else: | |
| # st.text('Death') |