|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import pickle |
|
import json |
|
|
|
|
|
|
|
|
|
|
|
with open('list_num_cols.txt', 'r') as file_1: |
|
list_num_cols = json.load(file_1) |
|
with open('list_cat_cols.txt', 'r') as file_2: |
|
list_cat_cols = json.load(file_2) |
|
with open('model_svm.pkl', 'rb') as file_3: |
|
model_svm = pickle.load(file_3) |
|
|
|
def run(): |
|
|
|
with st.form('credit_cards_simulation'): |
|
|
|
LimitBalance = st.number_input('Limit Balance', value = 0) |
|
|
|
Sex = st.number_input('Sex', min_value = 1, max_value = 2, value = 1, step = 1, help = '1 = Male, 2 = Female') |
|
|
|
EducationLevel = st.number_input('Education', min_value = 1, max_value = 6, value = 1, step = 1, help = '1 = Graduate School, 2 = University, 3 = High School, 4 = Other, 5 = Unknown, 6 = Unknown') |
|
|
|
MaritalStatus = st.number_input('Marital Status', min_value = 1, max_value = 3, value = 1, step = 1, help = '1 = Married, 2 = Single, 3 = Other') |
|
|
|
Age = st.slider('Age', 18, 70, 25) |
|
|
|
st.markdown('----') |
|
|
|
|
|
Pay_0 = st.number_input('Pay 1', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment Status in September, 2025 (-2 = No Transaction, -1 = Pay Duly, 1-9 = Payment Delay 1-9 Month)') |
|
|
|
Pay_2 = st.number_input('Pay 2', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in August, 2005 (scale same as above)') |
|
|
|
Pay_3 = st.number_input('Pay 3', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in July, 2005 (scale same as above)') |
|
|
|
Pay_4 = st.number_input('Pay 4', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in June, 2005 (scale same as above)') |
|
|
|
Pay_5 = st.number_input('Pay 5', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in May, 2005 (scale same as above)') |
|
|
|
Pay_6 = st.number_input('Pay 6', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in April, 2005 (scale same as above)') |
|
|
|
Bill_amt_1 = st.number_input('Amount Of Bill 1', value = 0 , help = 'Amount of bill statement in September, 2005 (NT dollar)') |
|
|
|
Bill_amt_2 = st.number_input('Amount Of Bill 2', value = 0, help = 'Amount of bill statement in August, 2005 (NT dollar)') |
|
Bill_amt_3 = st.number_input('Amount Of Bill 3', value = 0, help = 'Amount of bill statement in July, 2005 (NT dollar)') |
|
Bill_amt_4 = st.number_input('Amount Of Bill 4', value = 0, help = 'Amount of bill statement in June, 2005 (NT dollar)') |
|
Bill_amt_5 = st.number_input('Amount Of Bill 5', value = 0, help = 'Amount of bill statement in May, 2005 (NT dollar)') |
|
Bill_amt_6 = st.number_input('Amount Of Bill 6', value = 0, help = 'Amount of bill statement in April, 2005 (NT dollar)') |
|
|
|
Pay_amt_1 = st.number_input('Amount of previous payment 1', value = 0, help = 'Amount of previous payment in September, 2005 (NT dollar)') |
|
Pay_amt_2 = st.number_input('Amount of previous payment 2', value = 0, help = 'Amount of previous payment in August, 2005 (NT dollar)') |
|
Pay_amt_3 = st.number_input('Amount of previous payment 3', value = 0, help = 'Amount of previous payment in July, 2005 (NT dollar)') |
|
Pay_amt_4 = st.number_input('Amount of previous payment 4', value = 0, help = 'Amount of previous payment in June, 2005 (NT dollar)') |
|
Pay_amt_5 = st.number_input('Amount of previous payment 5', value = 0, help = 'Amount of previous payment in May, 2005 (NT dollar)') |
|
Pay_amt_6 = st.number_input('Amount of previous payment 6', value = 0, help = 'Amount of previous payment in April, 2005 (NT dollar)') |
|
|
|
|
|
|
|
submitted = st.form_submit_button('Predict') |
|
|
|
|
|
data_inf = { |
|
'limit_balance': LimitBalance, |
|
'sex': Sex, |
|
'education_level': EducationLevel, |
|
'marital_status': MaritalStatus, |
|
'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, |
|
'bill_amt_1' :Bill_amt_1, |
|
'bill_amt_2':Bill_amt_2, |
|
'bill_amt_3':Bill_amt_3, |
|
'bill_amt_4':Bill_amt_4, |
|
'bill_amt_5':Bill_amt_5, |
|
'bill_amt_6':Bill_amt_6, |
|
'pay_amt_1':Pay_amt_1, |
|
'pay_amt_2':Pay_amt_2, |
|
'pay_amt_3':Pay_amt_3, |
|
'pay_amt_4':Pay_amt_4, |
|
'pay_amt_5':Pay_amt_5, |
|
'pay_amt_6':Pay_amt_6, |
|
|
|
} |
|
|
|
data_inf = pd.DataFrame([data_inf]) |
|
st.dataframe(data_inf) |
|
|
|
|
|
|
|
if submitted: |
|
|
|
data_inf_num = data_inf[list_num_cols] |
|
data_inf_cat = data_inf[list_cat_cols] |
|
|
|
|
|
data_inf_final = data_inf_num |
|
|
|
|
|
y_pred_inf = model_svm.predict(data_inf_final) |
|
|
|
st.write('## Payment : ', str(int(y_pred_inf))) |
|
|
|
if __name__ == '__main__': |
|
run() |