Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import pickle | |
import json | |
# load all files | |
with open('cat_model.pkl', 'rb') as file_1: | |
cat_model = pickle.load(file_1) | |
# Pre-processing | |
with open('scale_feat.pkl', 'rb') as file_2: | |
scale_feat = pickle.load(file_2) | |
with open('winsoriser.pkl', 'rb') as file_3: | |
winsoriser = pickle.load(file_3) | |
# List Numeric & Category | |
with open('num_cols_sc.txt', 'r') as file_4: | |
num_cols_sc = json.load(file_4) | |
with open('num_cols_nsc.txt', 'r') as file_5: | |
num_cols_nsc = json.load(file_5) | |
def run(): | |
with st.form(key='from_health'): | |
age = st.number_input('Usia', min_value=25, max_value=95, | |
value=40, step=1, help='Usia Pasien') | |
anaemia = st.number_input('Anemia', min_value=0, max_value=1, | |
value=0, step=1, help='Terindikasi Anemia 0 = Tidak, 1 = Ya') | |
creatinine_phosphokinase = st.slider('Creatine Value', 0, 10_000, 1500, step=20, help='Kadar Creatinine') | |
diabetes = st.number_input('Diabetes', min_value=0, max_value=1, | |
value=0, step=1, help='Terindikasi Diabetes 0 = Tidak, 1 = Ya') | |
ejection_fraction = st.number_input('Ejection Value', min_value=0, max_value=100, | |
value=50, step=1, help='Kadar Ejection') | |
high_blood_pressure = st.number_input('Tekanan Darah Tinggi', min_value=0, max_value=1, | |
value=0, step=1, help='Terindikasi Tekanan Darah Tinggi 0 = Tidak, 1 = Ya') | |
platelets = st.slider('Platelets', 0, 850_000, 50_000, step=100, help='Kadar Platelets') | |
serum_creatinine = st.number_input('Serum Creatinine', min_value=0, max_value=10, | |
value=5, step=1, help='Kadar Serum_Creatinine') | |
serum_sodium = st.number_input('Serum Sodium', min_value=0, max_value=150, | |
value=50, step=1, help='Kadar Serum_Sodium') | |
sex = st.number_input('Jenis Kelamin', min_value=0, max_value=1, | |
value=0, step=1, help='Kode jenis kelamin 0 = wanita , 1 = pria') | |
smoking = st.number_input('Merokok', min_value=0, max_value=1, | |
value=0, step=1, help='Terindikasi Merokok 0 = Tidak, 1 = Ya') | |
time = st.number_input('Waktu', min_value=0, max_value=300, | |
value=10, step=1, help='Waktu berkunjung kembali') | |
st.markdown('---') | |
submitted = st.form_submit_button('Predict') | |
data_inf = { | |
'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, | |
} | |
st.markdown('Jika Hasil Prediksi = 1, maka model memprediksi bahwa pasien akan meninggal.') | |
st.markdown('Jika Hasil Prediksi = 1, maka model memprediksi bahwa pasien akan meninggal.') | |
data_inf = pd.DataFrame([data_inf]) | |
st.dataframe(data_inf) | |
if submitted: | |
data_inf_sc = data_inf[num_cols_sc] | |
data_inf_nsc = data_inf[num_cols_nsc] | |
# scalling | |
data_inf_sc = scale_feat.transform(data_inf_sc) | |
data_inf_sc = pd.DataFrame(data_inf_sc, columns=num_cols_sc) | |
# Reset Index | |
data_inf_sc.reset_index(drop= True, inplace= True) | |
data_inf_nsc.reset_index(drop = True, inplace = True) | |
data_final = pd.concat([data_inf_nsc, data_inf_sc], axis= 1) | |
# modeling | |
y_pred_inf = cat_model.predict(data_final) | |
st.write('Prediction: ', (y_pred_inf)) | |
if __name__ == '__main__': | |
run() |