File size: 2,623 Bytes
309d3ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# import library
import streamlit as st
import pandas as pd
import numpy as np
import pickle

# Load Model
with open('model.pkl', 'rb') as file:
    model = pickle.load(file)

# Function untuk menjalankan streamlit model predictor
def run():

   # Set judul
    st.title("Memprediksi Kemungkinan Seseorang Mampu Membayar Kredit atau Tidak")
    st.markdown('---')
    st.image("https://dlabs.ai/wp-content/uploads/2021/09/price-prediction-1024x538.png")

    # Buat Form Untuk Data Inference
    st.markdown('## Input Data')
    with st.form('my_form'):
        Limit_balance = st.number_input('Limit Balance', min_value=10000, max_value=999999999)
        Pay_1 = st.selectbox('Repayment Status in September', (-2,-1,0,1,2,3,4,5,6,7,8))
        Pay_2 = st.selectbox('Repayment Status in August', (-2,-1,0,1,2,3,4,5,6,7,8))
        Pay_3 = st.selectbox('Repayment Status in July', (-2,-1,0,1,2,3,4,5,6,7,8))
        Pay_4 = st.selectbox('Repayment Status in June', (-2,-1,0,1,2,3,4,5,6,7,8))
        Pay_5 = st.selectbox('Repayment Status in May', (-2,-1,0,1,2,3,4,5,6,7,8))
        Pay_6 = st.selectbox('Repayment Status in April', (-2,-1,0,1,2,3,4,5,6,7,8))
        Pay_amt_1 = st.number_input('Bill Statement in September', min_value=-999999999, max_value=999999999)
        Pay_amt_2 = st.number_input('Bill Statement in August', min_value=-999999999, max_value=999999999)
        Pay_amt_3 = st.number_input('Bill Statement in July', min_value=-999999999, max_value=999999999)
        Pay_amt_4 = st.number_input('Bill Statement in June', min_value=-999999999, max_value=999999999)
        Pay_amt_5 = st.number_input('Bill Statement in May', min_value=-999999999, max_value=999999999)
        Pay_amt_6 = st.number_input('Bill Statement in April', min_value=-999999999, max_value=999999999)

        # Membuat tombol untuk melakukan prediksi
        submitted = st.form_submit_button("Predict")

    # dataframe
    data = {'limit_balance': Limit_balance,
            'pay_1': Pay_1,
            'pay_2': Pay_2,
            'pay_3': Pay_3,
            'pay_4': Pay_4,
            'pay_5': Pay_5,
            'pay_6': Pay_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}

    df = pd.DataFrame([data])
    st.dataframe(df)

    if submitted:
        y_pred_inf = model.predict(df)
        if y_pred_inf[0] == 0:
            st.write('✅ Tidak Gagal Bayar')
        else:
            st.write('❌ Gagal Bayar')

if __name__== '__main__':
    run()