Destri2000 commited on
Commit
843fde4
1 Parent(s): 2ac6a9d
Files changed (8) hide show
  1. app.py +10 -0
  2. eda.py +40 -0
  3. image.jpg +0 -0
  4. knn_tun.pkl +3 -0
  5. model_encoder_ordinal.pkl +3 -0
  6. model_scaler.pkl +3 -0
  7. prediction.py +127 -0
  8. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ page = st.sidebar.selectbox('Pilih Halaman: ', ('EDA', 'Prediction'))
6
+
7
+ if page == 'EDA':
8
+ eda.run()
9
+ else:
10
+ prediction.run()
eda.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+ from PIL import Image
7
+
8
+ st.set_page_config(
9
+ page_title = 'Credit Card Customer Information'
10
+ )
11
+
12
+ def run():
13
+ #membuat judul
14
+ st.title('Prediction Customer Default Payment')
15
+
16
+ #tambahkan gambar
17
+ image = Image.open('image.jpg')
18
+ st.image(image, caption = 'Credit Card Loan')
19
+
20
+ #bikin garis pemisah
21
+ st.markdown('---')
22
+ st.write("Default payment refers to a customer's failure to make timely payments on their financial obligations according to agreed terms. In the context of a credit card or loan, a default payment occurs when a customer fails to pay the minimum amount due or the entire balance due on time.")
23
+ st.write("Defaulting on a credit card payment is a serious matter with potentially far-reaching consequences for the cardholder's financial health and creditworthiness. It is important for cardholders to manage their credit responsibly and make timely payments to avoid defaulting on their credit card accounts.")
24
+
25
+ st.markdown('---')
26
+ #Show dataframe
27
+ df = pd.read_csv('data.csv')
28
+ st.write('## Customer Credit Card Data')
29
+ st.dataframe(df[['sex', 'education_level', 'marital_status', 'age', 'limit_balance']])
30
+
31
+ #membuat histogram berdasarkan user input
32
+ st.write('## Histrogram Customer Credit Card')
33
+ option = st.selectbox('Select Column: ', ('sex', 'education_level', 'marital_status', 'age'))
34
+ fig = plt.figure(figsize=(15,5))
35
+ sns.histplot(df[option], bins = 30, kde = True)
36
+ st.pyplot(fig)
37
+
38
+
39
+ if __name__ == '__main__':
40
+ run()
image.jpg ADDED
knn_tun.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:338fcdf3177ab80f0b1c76322a8e99d74c0b4d0d98913015fef5025d56425032
3
+ size 325064
model_encoder_ordinal.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5d48829341a9293c8c3bfa61b70b620490033b9f161c518226fc4b496b38d68
3
+ size 557
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ff5726e6f7a2aabb7470e917853bd462ac4a8cccf21763bc0e9d24fb232f513
3
+ size 984
prediction.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+
6
+
7
+ with open('knn_tun.pkl', 'rb') as model_knn:
8
+ knn_tun = pickle.load(model_knn)
9
+
10
+ with open('model_scaler.pkl', 'rb') as model_scaler:
11
+ model_scaler = pickle.load(model_scaler)
12
+
13
+ with open('model_encoder_ordinal.pkl', 'rb') as model_encoder_ordinal:
14
+ model_encoder_ordinal = pickle.load(model_encoder_ordinal)
15
+
16
+
17
+
18
+
19
+ def run():
20
+ #buat form inputan
21
+ with st.form('form_ credit_card_loan'):
22
+ st.write('### Personal Customer Information')
23
+ sex = st.selectbox('Sex',('Male', 'Female'))
24
+ age = st.number_input('Age', min_value = 16, max_value = 70, value = 20)
25
+ education_level = st.selectbox('Education',('Graduate School', 'University', 'High School', 'Others', 'Unknown'))
26
+ marital_status = st.selectbox('Marital Status',('Married', 'Single', 'Unknown'))
27
+ limit_balance = st.number_input('Limit Balance', min_value = 0, max_value = 1000000, value = 50)
28
+
29
+ st.markdown('---')
30
+
31
+ st.write('### Historical Payment Status Over 6 Months')
32
+ payment_options = {
33
+ "Pay two months in advance": -2,
34
+ "Pay one month in advance": -1,
35
+ "Pay on time": 0,
36
+ "Payment overdue by 1 month": 1,
37
+ "Payment overdue by 2 months": 2,
38
+ "Payment overdue by 3 months": 3,
39
+ "Payment overdue by 4 months": 4,
40
+ "Payment overdue by 5 months": 5,
41
+ "Payment overdue by 6 months": 6,
42
+ "Payment overdue by 7 months": 7
43
+ }
44
+ selected_pay_1 = st.selectbox('##### Payment Status in 1st Month', list(payment_options.keys()), index = 2)
45
+ selected_pay_2 = st.selectbox('##### Payment Status in 2nd Month', list(payment_options.keys()), index = 2)
46
+ selected_pay_3 = st.selectbox('##### Payment Status in 3rd Month', list(payment_options.keys()), index = 2)
47
+ selected_pay_4 = st.selectbox('##### Payment Status in 4th Month', list(payment_options.keys()), index = 2)
48
+ selected_pay_5 = st.selectbox('##### Payment Status in 5th Month', list(payment_options.keys()), index = 2)
49
+ selected_pay_6 = st.selectbox('##### Payment Status in 6th Month', list(payment_options.keys()), index = 2)
50
+
51
+ pay_1 = payment_options[selected_pay_1]
52
+ pay_2 = payment_options[selected_pay_2]
53
+ pay_3 = payment_options[selected_pay_3]
54
+ pay_4 = payment_options[selected_pay_4]
55
+ pay_5 = payment_options[selected_pay_5]
56
+ pay_6 = payment_options[selected_pay_6]
57
+
58
+ st.write('### Historical Bill Records Over 6 Months')
59
+ bill_amt_1 = st.number_input('##### Amount of the Bill in 1st Month', min_value = 0, max_value = 1000000, value = 0)
60
+ bill_amt_2 = st.number_input('##### Amount of the Bill in 2nd Month', min_value = 0, max_value = 1000000, value = 0)
61
+ bill_amt_3 = st.number_input('##### Amount of the Bill in 3rd Month', min_value = 0, max_value = 1000000, value = 0)
62
+ bill_amt_4 = st.number_input('##### Amount of the Bill in 4th Month', min_value = 0, max_value = 1000000, value = 0)
63
+ bill_amt_5 = st.number_input('##### Amount of the Bill in 5th Month', min_value = 0, max_value = 1000000, value = 0)
64
+ bill_amt_6 = st.number_input('##### Amount of the Bill in 6th Month', min_value = 0, max_value = 1000000, value = 0)
65
+
66
+ st.write('### Historical Payment Records Over 6 Months')
67
+ pay_amt_1 = st.number_input('##### Amount of the Payment in 1st Month', min_value = 0, max_value = 1000000, value = 0)
68
+ pay_amt_2 = st.number_input('##### Amount of the Payment in 2nd Month', min_value = 0, max_value = 1000000, value = 0)
69
+ pay_amt_3 = st.number_input('##### Amount of the Payment in 3rd Month', min_value = 0, max_value = 1000000, value = 0)
70
+ pay_amt_4 = st.number_input('##### Amount of the Payment in 4th Month', min_value = 0, max_value = 1000000, value = 0)
71
+ pay_amt_5 = st.number_input('##### Amount of the Payment in 5th Month', min_value = 0, max_value = 1000000, value = 0)
72
+ pay_amt_6 = st.number_input('##### Amount of the Payment in 6th Month', min_value = 0, max_value = 1000000, value = 0)
73
+
74
+ #submit button
75
+ submitted = st.form_submit_button("Predict")
76
+
77
+
78
+ data_inf = {
79
+ 'sex' : sex,
80
+ 'age' : age,
81
+ 'education_level' : education_level,
82
+ 'marital_status' : marital_status,
83
+ 'limit_balance' : limit_balance,
84
+ 'pay_0' : pay_1,
85
+ 'pay_2' : pay_2,
86
+ 'pay_3' : pay_3,
87
+ 'pay_4' : pay_4,
88
+ 'pay_5' : pay_5,
89
+ 'pay_6' : pay_6,
90
+ 'bill_amt_1' : bill_amt_1,
91
+ 'bill_amt_2' : bill_amt_2,
92
+ 'bill_amt_3' : bill_amt_3,
93
+ 'bill_amt_4' : bill_amt_4,
94
+ 'bill_amt_5' : bill_amt_5,
95
+ 'bill_amt_6' : bill_amt_6,
96
+ 'pay_amt_1' : pay_amt_1,
97
+ 'pay_amt_2' : pay_amt_2,
98
+ 'pay_amt_3' : pay_amt_3,
99
+ 'pay_amt_4' : pay_amt_4,
100
+ 'pay_amt_5' : pay_amt_5,
101
+ 'pay_amt_6' : pay_amt_6
102
+ }
103
+
104
+ data_inf = pd.DataFrame([data_inf])
105
+
106
+ if submitted:
107
+ #split between numerical and categorical columns
108
+ list_num_column = ['limit_balance', 'pay_0', 'pay_2', 'pay_3', 'pay_4',
109
+ 'pay_5', 'pay_6', 'pay_amt_1', 'pay_amt_2', 'pay_amt_3', 'pay_amt_4',
110
+ 'pay_amt_5', 'pay_amt_6']
111
+ list_cat_col_ordinal = ['education_level']
112
+ data_inf_num = data_inf[list_num_column]
113
+ data_inf_cat = data_inf[list_cat_col_ordinal]
114
+ #feature scaling and encoding
115
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
116
+ data_inf_cat_encoded = model_encoder_ordinal.transform(data_inf_cat)
117
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)
118
+ # predict using linear reg model
119
+ y_pred_inf = knn_tun.predict(data_inf_final)
120
+ if y_pred_inf == 0:
121
+ st.write('## Prediction: The customers are predicted to encounter delayed payments next month')
122
+ else :
123
+ st.write('## Prediction: Customers are predicted to pay on time next month')
124
+
125
+
126
+ if __name__ == '__main__':
127
+ run()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ seaborn
5
+ matplotlib
6
+ Pillow
7
+ plotly
8
+ scikit-learn==1.2.2