|
|
|
|
|
|
|
import streamlit as st |
|
import pandas as pd |
|
import pickle |
|
|
|
|
|
with open('scaler.pkl', 'rb') as file_1: |
|
scaler = pickle.load(file_1) |
|
|
|
with open('model.pkl', 'rb') as file_2: |
|
model = pickle.load(file_2) |
|
|
|
|
|
def run(): |
|
|
|
with st.form('Form_CreditDefaultPredictor'): |
|
|
|
limit_balance = st.number_input('limit_balance',min_value=10000, max_value=1000000) |
|
|
|
age = st.number_input('age', min_value= 21, max_value = 70, step = 1, help = 'Age of borrower') |
|
|
|
education_level = st.slider('education_level', 1, 4, 2) |
|
st.write('#### - 1 is graduate school') |
|
st.write('#### - 2 is university') |
|
st.write('#### - 3 is high school') |
|
st.write('#### - 4 is others') |
|
|
|
marital_status = st.slider('marital_status', 1, 3, 2) |
|
st.write('#### - 1 is married') |
|
st.write('#### - 2 is single') |
|
st.write('#### - 3 is others') |
|
|
|
pay_0 = st.slider('pay_0', -2, 9, -1 ) |
|
st.write('### latest month payment status') |
|
st.write('#### - -2: pay early') |
|
st.write('#### - -1 = pay on deadline') |
|
st.write('#### - 0 : pay delayed for 0 month') |
|
st.write('#### - 1 = payment delayed for one month') |
|
st.write('#### - 2 = payment delayed for two months') |
|
st.write('#### ...') |
|
st.write('#### - 8 = payment delayed for 8 months') |
|
st.write('#### - 9 = payment delayed for 9 months') |
|
|
|
pay_2 = st.slider('pay_1', -2, 9, -1, key=2 ) |
|
st.write('#### 1 months before latest month payment status, same scale as above') |
|
|
|
pay_3 = st.slider('pay_2', -2, 9, -1, key=3 ) |
|
st.write('#### 2 months before latest month payment status, same scale as above') |
|
|
|
pay_4 = st.slider('pay_3', -2, 9, -1, key=4 ) |
|
st.write('#### 3 months before latest month payment status, same scale as above') |
|
|
|
pay_5 = st.slider('pay_4', -2, 9, -1, key=5 ) |
|
st.write('#### 4 months before latest month payment status, same scale as above') |
|
|
|
pay_6 = st.slider('pay_5', -2, 9, -1, key=6 ) |
|
st.write('#### 5 months before latest month payment status, same scale as above') |
|
|
|
st.markdown('---------') |
|
|
|
submitted = st.form_submit_button('Predict!') |
|
|
|
|
|
|
|
|
|
data_inf = { |
|
'limit_balance' : limit_balance, |
|
'education_level' : education_level, |
|
'marital_status' : marital_status, |
|
'age': age, |
|
'pay_0' : pay_0, |
|
'pay_2' : pay_2, |
|
'pay_3' : pay_3, |
|
'pay_4' : pay_4, |
|
'pay_5' : pay_5, |
|
'pay_6' : pay_6, |
|
} |
|
|
|
|
|
data_inf = pd.DataFrame([data_inf]) |
|
|
|
st.dataframe(data_inf) |
|
|
|
|
|
if submitted: |
|
|
|
data_inf_scaled = scaler.transform(data_inf) |
|
|
|
|
|
y_pred_inf = model.predict(data_inf_scaled) |
|
|
|
|
|
st.write('## Prediction of whether the borrower will default : ',str(int(y_pred_inf))) |
|
st.write('###1 = will default, 0 = will not default') |
|
if __name__ == '__main__': |
|
run() |