|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import pickle |
|
import json |
|
from joblib import load |
|
|
|
|
|
|
|
loaded_model_RF = load('model_RF.joblib') |
|
loaded_model_boost = load('model_boost.joblib') |
|
with open('col_penting.txt', 'r') as file_1: |
|
col = json.load(file_1) |
|
|
|
|
|
def run(): |
|
with st.form('key=form_Heart_failure_prediction'): |
|
age = st.number_input('Age', min_value=40, max_value=100, value=45, step=1, help='Usia Pasien') |
|
anaemia = st.radio('anaemia', (0,1), index=0,help='0 = No, 1 = Yes') |
|
creatinine_phosphokinase = st.slider('creatinine phosphokinase', 20, 1500, 200) |
|
diabetes = st.radio('diabetes', (0,1), index=1,help='0 = No, 1 = Yes') |
|
st.markdown('---') |
|
|
|
ejection_fraction = st.slider('ejection_fraction', 14, 80, 25) |
|
high_blood_pressure = st.radio('high blood pressure', (0,1), index=0,help='0 = No, 1 = Yes') |
|
platelets = st.slider('platelets', 25000, 850000, 100000) |
|
serum_creatinine = st.number_input('serum creatinine', min_value=0.5, max_value=2.5, value=0.75, step=0.05) |
|
serum_sodium = st.number_input('serum sodium', min_value=110, max_value=150, value=125, step=1) |
|
sex = st.selectbox('sex', (0,1), index=1,help='0 = Female, 1 = Male') |
|
smoking = st.selectbox('smoking', (0,1), index=0,help='0 = No, 1 = Yes') |
|
time = st.slider('time', 3, 300, 30) |
|
model = st.radio('pilih jenis model yang akan digunakan untuk prediksi :',('Random Forest', 'AdaBoost'),index=1) |
|
|
|
submitted = st.form_submit_button('Predict') |
|
|
|
data_inf = { |
|
'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 |
|
} |
|
|
|
data_inf = pd.DataFrame([data_inf]) |
|
inf_new = data_inf[col] |
|
if model == 'AdaBoost': |
|
if submitted: |
|
y_pred_inf = loaded_model_boost.predict(inf_new) |
|
st.write('# Death : ', str(int(y_pred_inf))) |
|
else : |
|
if submitted: |
|
y_pred_inf = loaded_model_RF.predict(inf_new) |
|
st.write('# Death : ', str(int(y_pred_inf))) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
run() |
|
|