File size: 3,802 Bytes
5eff680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# learn stremlit, this one for the predictions

#import libs
import streamlit as st
import pandas as pd
import pickle

#open related files/load files
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():
    #Make the input form for the user to input data?
    with st.form('Form_CreditDefaultPredictor'):
        #Field limit balance
        limit_balance = st.number_input('limit_balance',min_value=10000, max_value=1000000)
        #Field age
        age = st.number_input('age', min_value= 21, max_value = 70, step = 1, help = 'Age of borrower')
        #Field education level
        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')
        #Field marital status
        marital_status = st.slider('marital_status', 1, 3, 2)
        st.write('#### - 1 is married')
        st.write('#### - 2 is single')
        st.write('#### - 3 is others')
        #Field pay_0
        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')
        #Field pay_2
        pay_2 = st.slider('pay_1', -2, 9, -1, key=2 )
        st.write('#### 1 months before latest month payment status, same scale as above')
        #Field pay_3
        pay_3 = st.slider('pay_2', -2, 9, -1, key=3 )
        st.write('#### 2 months before latest month payment status, same scale as above')
        #Field pay_4
        pay_4 = st.slider('pay_3', -2, 9, -1, key=4 )
        st.write('#### 3 months before latest month payment status, same scale as above')
        #Field pay_5
        pay_5 = st.slider('pay_4', -2, 9, -1, key=5 )
        st.write('#### 4 months before latest month payment status, same scale as above')
        #Field pay_6
        pay_6 = st.slider('pay_5', -2, 9, -1, key=6 )
        st.write('#### 5 months before latest month payment status, same scale as above')
        # bikin batasan
        st.markdown('---------')
        #bikin submit button
        submitted = st.form_submit_button('Predict!')

    #inference/satuin data supaya bisa masuk model
    # nama col ('Name',etc) harus sama dengan di model
    # keys dari col harus sama dengan nama variable di form streamlit
    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,
    }

    #turn to dataframe for model
    data_inf = pd.DataFrame([data_inf])
    #aslo show the input from user
    st.dataframe(data_inf)

    #what happen when predict button is pushed/clicked:
    if submitted: #ketika si submitted itu punya value, maka
        #scale 
        data_inf_scaled = scaler.transform(data_inf)
        
        # predict using linear reg model
        y_pred_inf = model.predict(data_inf_scaled)

        #kasih tau hasilnya apa
        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()