|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import pickle |
|
import json |
|
from PIL import Image |
|
|
|
|
|
with open('list_kat.txt', 'r') as file_1: |
|
list_kat = json.load(file_1) |
|
|
|
with open('list_num.txt', 'r') as file_2: |
|
list_num = json.load(file_2) |
|
|
|
with open('scaler.pkl', 'rb') as file_3: |
|
scaler = pickle.load(file_3) |
|
|
|
with open('ohe.pkl', 'rb') as file_4: |
|
ohe = pickle.load(file_4) |
|
|
|
with open('model_SVM.pkl', 'rb') as file_5: |
|
model_svm = pickle.load(file_5) |
|
|
|
def run(): |
|
|
|
st.title('Credit Card prediction') |
|
|
|
st.subheader('Tugas GC5') |
|
with st.form('Form_credit_prediciton'): |
|
limit_balance = st.number_input('Limit Balance', value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
sex = st.number_input('sex',value=1 ,help='1=male, 2=female',min_value=1,max_value=2, format='%d') |
|
education_level= st.number_input('education level',value=1,help='1=graduate school, 2=university, 3=high school, 4=others, 5=unknown',min_value=1,max_value=5,format='%d') |
|
marital_status= st.number_input('Marital status',value=2,help='1=married, 2=single, 3=others',min_value=1,max_value=3,format='%d') |
|
age= st.number_input('Age',value=15,help='Umur anda',min_value=1,max_value=99) |
|
pay_0= st.number_input('pay_0',value=1,help='-1=pay duly, 1=payment delay for one month, 2=payment delay for two months,...',min_value=-1,max_value=8) |
|
pay_2= st.number_input('pay_2',value=1,help='-1=pay duly, 1=payment delay for one month, 2=payment delay for two months,...',min_value=-1,max_value=8) |
|
pay_3= st.number_input('pay_3',value=1,help='-1=pay duly, 1=payment delay for one month, 2=payment delay for two months,...',min_value=-1,max_value=8) |
|
pay_4= st.number_input('pay_4',value=1,help='-1=pay duly, 1=payment delay for one month, 2=payment delay for two months,...',min_value=-1,max_value=8) |
|
pay_5= st.number_input('pay_5',value=1,help='-1=pay duly, 1=payment delay for one month, 2=payment delay for two months,...',min_value=-1,max_value=8) |
|
pay_6= st.number_input('pay_6',value=1,help='-1=pay duly, 1=payment delay for one month, 2=payment delay for two months,...',min_value=-1,max_value=8) |
|
bill_amt_1= st.number_input('bill_amt_1',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
bill_amt_2= st.number_input('bill_amt_2',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
bill_amt_3= st.number_input('bill_amt_3',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
bill_amt_4= st.number_input('bill_amt_4',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
bill_amt_5= st.number_input('bill_amt_5',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
bill_amt_6= st.number_input('bill_amt_6',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
pay_amt_1= st.number_input('pay_amt_1',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
pay_amt_2= st.number_input('pay_amt_2',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
pay_amt_3= st.number_input('pay_amt_3',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
pay_amt_4= st.number_input('pay_amt_4',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
pay_amt_5= st.number_input('pay_amt_5',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
pay_amt_6= st.number_input('pay_amt_6',value = 10000000, help='numerik int ribuan lebih', min_value = 1000) |
|
|
|
|
|
submitted = st.form_submit_button('Predict') |
|
|
|
data_inf = { |
|
'limit_balance' : limit_balance, |
|
"sex" : sex, |
|
"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, |
|
'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] |
|
data_inf_kat = data_inf[list_kat] |
|
|
|
|
|
data_inf_scaled = scaler.transform(data_inf_num) |
|
data_inf_encoding = ohe.transform(data_inf_kat) |
|
nama_fitur=ohe.get_feature_names_out() |
|
data_inf_encoding=data_inf_encoding.toarray() |
|
|
|
data_inf_final = np.concatenate([data_inf_scaled,data_inf_encoding], axis = 1) |
|
|
|
|
|
|
|
y_pred_inf = model_svm.predict(data_inf_final) |
|
|
|
st.write('## Default payment: ', str(int(y_pred_inf))) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
run() |