P1G5_Dhani / model.py
achmaddhani's picture
Upload 10 files
5ab7542
'''
Phase 1 Graded Challenge 5
Nama : Achmad Dhani
Batch : HCK-009
Objective : Creating a specific page for model page and able to predict data that has been inputted
'''
import streamlit as st
import pandas as pd
import joblib
from PIL import Image
def run():
'''
This function is to run the model part for the main page
'''
model = joblib.load("best_model.pkl") # loading the model
options_dict = { # list of dictionaries for select box
"-2: Unused": -2,
"-1: Pay duly": -1,
"0: Revolving credit": 0,
"1: One month late payment": 1,
"2: Two months late payment": 2,
"3: Three months late payment": 3,
"4: Four months late payment": 4,
"5: Five months late payment": 5,
"6: Six months late payment": 6,
"7: Seven months late payment": 7,
"8: Eight months late payment": 8,
"9: Nine months or above late payment": 9
}
months = [ # list of months
'September 2005',
'August 2005',
'July 2005',
'June 2005',
'May 2005',
'April 2005'
]
balance = st.number_input(label='Input the limit balance here:',min_value=0,max_value=1000000) # balance input
data = {'limit_balance': balance} # balance data
for i, month in enumerate(months, 1): # accesing the month list and assigning it starting with 1
data[f'pay_{i}'] = options_dict[st.selectbox(f'Choose your repayment status in {month}:', list(options_dict.keys()))]
st.write('The following table is the result of the data you have input : ')
# display table
st.table(data)
df = pd.DataFrame([data])
# button
if st.button(label='Predict'):
y_pred_inf = model.predict(df)
# printing result
if y_pred_inf == 1:
st.write('The client will have a default payment')
else:
st.write('The client will **NOT** have a default payment')