File size: 5,473 Bytes
32f44b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import json

#Load All Files

#load model dan files yang sudah di save pada framing

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'):
        #Field Nama
        LimitBalance = st.number_input('Limit Balance', value = 0)
        #Field Umur
        Sex = st.number_input('Sex', min_value = 1, max_value = 2, value = 1, step = 1, help = '1 = Male, 2 = Female')
        #Field Tinggi badan
        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')
        #Field Weight
        MaritalStatus = st.number_input('Marital Status', min_value = 1, max_value = 3, value = 1, step = 1, help = '1 = Married, 2 = Single, 3 = Other')
        #field price
        Age = st.slider('Age', 18, 70, 25)

        st.markdown('----')

        #Field Attacking Work Rate
        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)')
        #Field Defensive Work Rate
        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)')
        #Field Pace Total
        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)')
        #Field Shooting Total
        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)')
        #Field Passing Total
        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)')
        #Field Dribbling Total
        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)')
        #Field Defending Total
        Bill_amt_1 = st.number_input('Amount Of Bill 1', value = 0 ,  help = 'Amount of bill statement in September, 2005 (NT dollar)')
        #Field Physicality Total
        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)')
        #Field Pay AMT
        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)')


        #bikin submit button
        submitted = st.form_submit_button('Predict')

    #Inference
    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)

    #Logic ketika predic button ditekan

    if submitted:
        #split between numerical and categorical columns
        data_inf_num = data_inf[list_num_cols]
        data_inf_cat = data_inf[list_cat_cols]
        
        #Scaling & Encoding
        data_inf_final = data_inf_num

        #predict using linear reg model
        y_pred_inf = model_svm.predict(data_inf_final)
        
        st.write('## Payment : ', str(int(y_pred_inf)))

if __name__ == '__main__':
   run()