GC3_Hacktiv8_FTDS_RMT17 / prediction.py
Evan Derin Ihsanudin
GC3_Deployment_Evan_Derin_Ihsanudin
d305ca4
import streamlit as st
import pandas as pd
import numpy as np
import pickle
# Load All Files
with open('windsorizer.pkl', 'rb') as file_1:
winsorizer_inf = pickle.load(file_1)
with open('scaler_final.pkl', 'rb') as file_2:
scaler_final = pickle.load(file_2)
with open('model_forest_opt.pkl', 'rb') as file_3:
model_forest_opt = pickle.load(file_3)
def run() :
# Membuat Title
st.markdown("<h1 style='text-align: center; color: black;'>Death Event Prediction</h1>", unsafe_allow_html=True)
# Menambahkan Deskripsi
st.write('Page ini berisi model untuk memprediksi *Death Event* (potensi meninggalnya pasien) dari pasien')
st.write('Mohon persiapkan **data Age, Creatinine Phosphokinase (mcg/L), Ejection Fraction (%), Platelets (kp/L), Serum Creatinine (mg/dl), Serum Sodium (mEq/L) dan Time (days) sesuai satuan yang tertera sebelum melakukan prediksi**')
#Membuat Form
with st.form(key= 'form_health_parameter'):
#Deklasrasi input
age = st.number_input('Age', min_value=40, max_value=100, value=40 ,step=1, help='Usia Pasien')
creatinine_phosphokinase = st.number_input('Creatinine Phospokinase (mcg/L)', min_value=20, max_value=8000, value=250 ,step=1, help='Kadar creatine kinase dalam darah (mcg/L)')
ejection_fraction = st.slider('Ejection Fraction (%)', min_value=10, max_value=100, value=40 ,step=1, help='Kemampuan jantung untuk memompa darah dengan oksigen ke seluruh tubuh (%)')
platelets = st.number_input('Platelets (kp/L)', min_value=25000, max_value=850000, value=250000 ,step=1, help='Jumlah trombosit pada darah (kp/L)')
serum_creatinine = st.number_input('Serum Creatinine (mg/dl)', min_value=1, max_value=10, value=1 ,step=1, help='Kadar Kreatinin (Zat Limbah) pada darah (mg/dl)')
serum_sodium = st.slider('Serum Sodium (mEq/L)', min_value=100, max_value=150, value=130 ,step=1, help='Kadar natrium serum pada darah (mEq/L)')
time = st.number_input('Time Follow Up (days)', min_value=1, max_value=300, value=100 ,step=1, help='Waktu Follow Up Pasien (days)')
#Membuat Button
submitted = st.form_submit_button('Predict')
#Membuat Data Inference
data_inf = {
'age': age,
'creatinine_phosphokinase': creatinine_phosphokinase,
'ejection_fraction': ejection_fraction,
'platelets': platelets,
'serum_creatinine': serum_creatinine,
'serum_sodium': serum_sodium,
'time': time
}
#Membuat Dataframe
data_inf = pd.DataFrame([data_inf])
data_inf
#Prediksi
if submitted :
#Windsoriser pada data inferencing dengan modul windsoriser
data_inf = winsorizer_inf.transform(data_inf)
#Feature Scaling
data_inf_final = scaler_final.transform(data_inf)
#Predict using Random Forest Parameter Tuning
y_pred_inf = model_forest_opt.predict(data_inf_final)
#Print hasil prediksi
if y_pred_inf == 1:
prediction = 'Deceased (Class 1)'
else:
prediction = 'Not Deceasead (Class 0)'
st.write('# Death Event : ', prediction)
if __name__ == '__main__':
run()