import streamlit as st import pandas as pd import numpy as np import joblib import ast st.title('Heart Failure Prediction') with open('model_scaler.pkl', 'rb') as file_1: model_scaler = joblib.load(file_1) with open('rf_best_model.pkl', 'rb') as file_2: rf_random_best = joblib.load(file_2) with open('list_num_col.txt', 'r') as file_3: num_col = file_3.read() with open('list_cat_col.txt', 'r') as file_4: cat_col = file_4.read() with open('boxcox.pkl', 'rb') as file_5: box = joblib.load(file_5) num_col = ast.literal_eval(num_col) cat_col = ast.literal_eval(cat_col) # time, ejection_fraction, age, serum creatinine, serum_sodium, creatinine_phosphokinase, diabetes, high_blood_pressure, smoking time = st.slider('Follow up perriod (days) : ',min_value=1,max_value=365,step=1) age = st.slider('Age : ', 30,120,step=1) ejection_fraction = st.number_input('Ejection Fraction : ',min_value=1,max_value=100,step=1) serum_creatinine = st.number_input('Serum Creatinine : ',min_value=0.0,max_value=10.0,step=0.01) serum_sodium = st.number_input('Serum Sodium : ',min_value=100,max_value=150,step=1) anaemia = st.radio('Anemia (1=Yes, 0=NO) : ',(1, 0)) diabetes = st.radio('Diabetes (1=Yes, 0=NO) : ',(1, 0)) smoking = st.radio('Smoking (1=Yes, 0=NO) : ',(1, 0)) if st.button('Predict'): data_inf = pd.DataFrame({'time':time, 'ejection_fraction':ejection_fraction, 'age':age, 'serum_creatinine':serum_creatinine, 'serum_sodium':serum_sodium, 'anaemia':anaemia, 'diabetes':diabetes, 'smoking':smoking },index=[0]) data_inf_t = box.transform(data_inf) data_inf_num = data_inf_t[num_col] data_inf_cat = data_inf_t[cat_col] data_inf_num_scaled = data_inf_num.copy() data_inf_num_scaled[num_col] = model_scaler.transform(data_inf_num[num_col]) data_inf_cat_encoded = data_inf_cat.copy() data_inf_num_scaled data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1) result = rf_random_best.predict(data_inf_final)[0] st.write('Predicted Result:') st.header(result)