|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import pickle |
|
import json |
|
|
|
|
|
with open("grid_1_best.pkl", "rb") as file_1: |
|
grid_1_best = pickle.load(file_1) |
|
|
|
with open("model_scaler.pkl", "rb") as file_2: |
|
model_scaler = pickle.load(file_2) |
|
|
|
with open("model_encoder_nominal.pkl", "rb") as file_4: |
|
model_encodern = pickle.load(file_4) |
|
|
|
with open("list_num_cols.txt", "r") as file_5: |
|
list_num_cols = json.load(file_5) |
|
|
|
with open("list_catn_cols.txt", "r") as file_6: |
|
list_catn_cols = json.load(file_6) |
|
|
|
with open("list_cato_cols.txt", "r") as file_7: |
|
list_cato_cols = json.load(file_7) |
|
|
|
|
|
def run(): |
|
|
|
with st.form(key="form_fifa_2022"): |
|
name = st.text_input("Name", value="") |
|
age = st.number_input("Age", min_value=16, max_value=120, value=30, step=1, help="Usia") |
|
st.markdown("---") |
|
sex = st.selectbox("Gender", ("Female", "Male"), index=1) |
|
anemia = st.selectbox("History of Anemia", ("Yes", "No"), index=1) |
|
diabetes = st.selectbox("History of Diabetes", ("Yes", "No"), index=1) |
|
hbd = st.selectbox("History of High Blood Pressure", ("Yes", "No"), index=1) |
|
smoking = st.selectbox("History of Smoking", ("Yes", "No"), index=1) |
|
st.markdown("---") |
|
creatinine_phosphokinase = st.number_input("Creatinine Phosphokinase", min_value=10, max_value=8000, value=1000, step=1, help="creatinine_phosphokinase") |
|
ejection_fraction = st.number_input("Ejection Fraction", min_value=5, max_value=200, value=50, step=1, help="ejection_fraction") |
|
platelets = st.number_input("platelets", min_value=20000, max_value=1000000, value=100000, step=1, help="platelets") |
|
serum_creatinine = st.number_input("serum_creatinine", min_value=0, max_value=15, value=2, step=1, help="serum_creatinine") |
|
serum_sodium = st.number_input("serum_sodium", min_value=50, max_value=300, value=100, step=1, help="serum_sodium") |
|
time = st.number_input("time", min_value=1, max_value=365, value=100, step=1, help="time") |
|
|
|
|
|
st.markdown("---") |
|
|
|
|
|
|
|
submitted = st.form_submit_button("Predict") |
|
|
|
data_inf = {'sex': [1 if x == "Male" else 0 for x in anemia], |
|
'umur': int((age-1)/5), |
|
'anaemia': [1 if x == "Yes" else 0 for x in anemia], |
|
'diabetes': [1 if x == "Yes" else 0 for x in diabetes], |
|
'high_blood_pressure': [1 if x == "Yes" else 0 for x in hbd], |
|
'smoking': [1 if x == "Yes" else 0 for x in smoking], |
|
'creatinine_phosphokinase': creatinine_phosphokinase, |
|
'ejection_fraction': ejection_fraction, |
|
'platelets': platelets, |
|
'serum_creatinine': serum_creatinine, |
|
'serum_sodium': serum_sodium, |
|
'time': time |
|
} |
|
|
|
|
|
|
|
data_inf = pd.DataFrame([data_inf]) |
|
st.dataframe(data_inf) |
|
|
|
if submitted: |
|
|
|
|
|
|
|
data_num = data_inf[list_num_cols] |
|
data_catn = data_inf[list_catn_cols] |
|
data_cato = data_inf[list_cato_cols] |
|
|
|
|
|
|
|
data_num_scaled = model_scaler.transform(data_num) |
|
data_catn_encoded = model_encodern.transform(data_catn).toarray() |
|
data_cato_encoded = data_cato |
|
data_final = np.concatenate([data_num_scaled, data_cato_encoded, data_catn_encoded], axis = 1) |
|
|
|
|
|
y_pred = grid_1_best.predict(data_final) |
|
|
|
st.write("# Rating : ", str(int(y_pred))) |
|
|
|
if __name__ == "__app__": |
|
run() |