Spaces:
Sleeping
Sleeping
Upload 11 files
Browse files- P1G5_Set_1_Darly_Purba.ipynb +0 -0
- app.py +10 -0
- best_pipe.pkl +3 -0
- cat_col.txt +1 -0
- credit_card_default.csv +0 -0
- dataset.csv +0 -0
- eda.py +114 -0
- image.png +0 -0
- num_col.txt +1 -0
- prediction.py +90 -0
- requirements.txt +9 -0
P1G5_Set_1_Darly_Purba.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
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()
|
best_pipe.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e28f18dca6ae109ea40a03b33973d4f5857b13d29c131bf10a0286af3f7b0119
|
3 |
+
size 197681
|
cat_col.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
[]
|
credit_card_default.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dataset.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
eda.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
def run():
|
9 |
+
# Membuat judul
|
10 |
+
st.title('Credit Card Default')
|
11 |
+
|
12 |
+
# Membuat Sub Header
|
13 |
+
st.header('EDA untuk Analisa Dataset Credit Card Default', divider='gray')
|
14 |
+
|
15 |
+
# Menambahkan Gambar
|
16 |
+
image = Image.open('image.png')
|
17 |
+
st.image(image, caption = 'Credit Card Default', channels='RGB')
|
18 |
+
|
19 |
+
# Menambahkan Divider
|
20 |
+
st.divider()
|
21 |
+
|
22 |
+
# Menampilkan Dataframe
|
23 |
+
st.header('Dataframe', divider='gray')
|
24 |
+
data = pd.read_csv('dataset.csv')
|
25 |
+
st.dataframe(data)
|
26 |
+
st.divider()
|
27 |
+
|
28 |
+
# Membuat Bar Plot 1
|
29 |
+
st.write('#### Hubungan Jenis Kelamin dengan Gagal Bayar')
|
30 |
+
fig = plt.figure(figsize=(12,8))
|
31 |
+
sns.barplot(x='sex', y='default_payment_next_month', data=data)
|
32 |
+
|
33 |
+
# Menambah Title dan Label
|
34 |
+
plt.title('Hubungan Jenis Kelamin dengan Gagal Bayar')
|
35 |
+
plt.xlabel('Jenis Kelamin')
|
36 |
+
plt.ylabel('Gagal Bayar')
|
37 |
+
|
38 |
+
# Menampilkan Plot
|
39 |
+
plt.tight_layout()
|
40 |
+
st.pyplot(fig)
|
41 |
+
|
42 |
+
# Keterangan
|
43 |
+
plot1 = '''Keterangan :
|
44 |
+
1 = Pria
|
45 |
+
2 = Wanita'''
|
46 |
+
st.markdown(plot1)
|
47 |
+
st.divider()
|
48 |
+
|
49 |
+
|
50 |
+
# Membuat Bar Plot 2
|
51 |
+
st.write('#### Hubungan Tingkat Pendidikan dengan Gagal Bayar')
|
52 |
+
fig = plt.figure(figsize=(12,8))
|
53 |
+
sns.barplot(x='education_level', y='default_payment_next_month', data=data)
|
54 |
+
|
55 |
+
# Menambah Title dan Label
|
56 |
+
plt.title('Hubungan Status Pernikahan dengan Gagal Bayar')
|
57 |
+
plt.xlabel('Status Pernikahan')
|
58 |
+
plt.ylabel('Gagal Bayar')
|
59 |
+
|
60 |
+
# Menampilkan Plot
|
61 |
+
plt.tight_layout()
|
62 |
+
st.pyplot(fig)
|
63 |
+
|
64 |
+
# Keterangan
|
65 |
+
plot2 = '''Keterangan :
|
66 |
+
1 = Graduate School, 2 = University, 3 = High School, 4 = Tidak Menjawab'''
|
67 |
+
st.markdown(plot2)
|
68 |
+
st.divider()
|
69 |
+
|
70 |
+
|
71 |
+
# Membuat Bar Plot 3
|
72 |
+
st.write('#### Hubungan Status Pernikahan dengan Gagal Bayar')
|
73 |
+
fig = plt.figure(figsize=(12,8))
|
74 |
+
sns.barplot(x='marital_status', y='default_payment_next_month', data=data)
|
75 |
+
|
76 |
+
# Menambah Title dan Label
|
77 |
+
plt.title('Hubungan Status Pernikahan dengan Gagal Bayar')
|
78 |
+
plt.xlabel('Status Pernikahan')
|
79 |
+
plt.ylabel('Gagal Bayar')
|
80 |
+
|
81 |
+
# Menampilkan Plot
|
82 |
+
plt.tight_layout()
|
83 |
+
st.pyplot(fig)
|
84 |
+
|
85 |
+
# Keterangan
|
86 |
+
plot3 = '''Keterangan :
|
87 |
+
1 = Menikah, 2 = Belum Menikah, 3 = Tidak Menjawab'''
|
88 |
+
st.markdown(plot3)
|
89 |
+
st.divider()
|
90 |
+
|
91 |
+
|
92 |
+
# Membuat Bar Plot 4
|
93 |
+
st.write('#### Status Pembayaran')
|
94 |
+
fig = plt.figure(figsize=(12,8))
|
95 |
+
sns.countplot(x='default_payment_next_month', data=data)
|
96 |
+
|
97 |
+
# Menambahkan label Sumbu dan judul
|
98 |
+
plt.xlabel('Status Pembayaran')
|
99 |
+
plt.ylabel('Count')
|
100 |
+
plt.title('Kemungkinan Nasabah Mengalami Kegagalan Pembayaran')
|
101 |
+
|
102 |
+
# Menampilkan Plot
|
103 |
+
plt.tight_layout()
|
104 |
+
st.pyplot(fig)
|
105 |
+
|
106 |
+
# Keterangan
|
107 |
+
plot4 = '''Keterangan :
|
108 |
+
0 = Membayar Tagihan, 1 = Gagal Membayar Tagihan'''
|
109 |
+
st.markdown(plot4)
|
110 |
+
st.divider()
|
111 |
+
|
112 |
+
|
113 |
+
if __name__ == '__main__':
|
114 |
+
run()
|
image.png
ADDED
![]() |
num_col.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
["limit_balance", "sex", "education_level", "marital_status", "age", "pay_1", "pay_2", "pay_3", "pay_4", "pay_5", "pay_6", "bill_amt_1", "bill_amt_2", "bill_amt_3", "bill_amt_4", "bill_amt_5", "bill_amt_6", "pay_amt_1", "pay_amt_2", "pay_amt_3", "pay_amt_4", "pay_amt_5", "pay_amt_6"]
|
prediction.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import json
|
6 |
+
|
7 |
+
#Load All files
|
8 |
+
#Load model
|
9 |
+
|
10 |
+
with open('best_pipe.pkl', 'rb') as file_1:
|
11 |
+
best_pipe = pickle.load(file_1)
|
12 |
+
with open('num_col.txt', 'r') as file_2:
|
13 |
+
num_col = json.load(file_2)
|
14 |
+
with open('cat_col.txt', 'r') as file_3:
|
15 |
+
cat_col = json.load(file_3)
|
16 |
+
|
17 |
+
def run():
|
18 |
+
|
19 |
+
with st.form('Credit_Card_Default'):
|
20 |
+
limit_balance = st.number_input('Limit Balance', value=80000)
|
21 |
+
sex = st.selectbox('Sex (1 = Male, 2 = Female)', (1, 2))
|
22 |
+
education_level = st.selectbox('Education Level (1 = Graduate School, 2 = University, 3 = High School, 4 = Others)', (1, 2, 3, 4))
|
23 |
+
marital_status = st.selectbox('Marital Status (1 = married, 2 = single, 3 = others)', (1, 2, 3))
|
24 |
+
age = st.number_input('Age', value = 25, min_value = 21, max_value = 69)
|
25 |
+
pay_1 = st.number_input('Repayment Status in September, 2005 (-2 = Others, -1 = Pay Duly, 1= Payment Delay for One Month, 2 = Payment Delay for Two Months, ... 8 = Payment Delay for Eight Months)', min_value=-2, max_value=8, value=3)
|
26 |
+
pay_2 = st.number_input('Repayment Status in August, 2005 (-2 = Others, -1 = Pay Duly, 1= Payment Delay for One Month, 2 = Payment Delay for Two Months, ... 8 = Payment Delay for Eight Months)', min_value=-2, max_value=7, value=3)
|
27 |
+
pay_3 = st.number_input('Repayment Status in July, 2005 (-2 = Others, -1 = Pay Duly, 1= Payment Delay for One Month, 2 = Payment Delay for Two Months, ... 8 = Payment Delay for Eight Months)', min_value=-2, max_value=7, value=3)
|
28 |
+
pay_4 = st.number_input('Repayment Status in June, 2005 (-2 = Others, -1 = Pay Duly, 1= Payment Delay for One Month, 2 = Payment Delay for Two Months, ... 8 = Payment Delay for Eight Months)', min_value=-2, max_value=8, value=3)
|
29 |
+
pay_5 = st.number_input('Repayment Status in May, 2005 (-2 = Others, -1 = Pay Duly, 1= Payment Delay for One Month, 2 = Payment Delay for Two Months, ... 8 = Payment Delay for Eight Months)', min_value=-2, max_value=7, value=3)
|
30 |
+
pay_6 = st.number_input('Repayment Status in April, 2005 (-2 = Others, -1 = Pay Duly, 1= Payment Delay for One Month, 2 = Payment Delay for Two Months, ... 8 = Payment Delay for Eight Months)', min_value=-2, max_value=7, value=3)
|
31 |
+
bill_amt_1 = st.number_input('Amount of bill statement in September, 2005', value=5000)
|
32 |
+
bill_amt_2 = st.number_input('Amount of bill statement in August, 2005', value=6000)
|
33 |
+
bill_amt_3 = st.number_input('Amount of bill statement in July, 2005', value=7000)
|
34 |
+
bill_amt_4 = st.number_input('Amount of bill statement in June, 2005', value=8000)
|
35 |
+
bill_amt_5 = st.number_input('Amount of bill statement in May, 2005', value=9000)
|
36 |
+
bill_amt_6 = st.number_input('Amount of bill statement in April, 2005', value=10000)
|
37 |
+
pay_amt_1 = st.number_input('Amount of bill statement in September, 2005', value=11000)
|
38 |
+
pay_amt_2 = st.number_input('Amount of bill statement in August, 2005', value=12000)
|
39 |
+
pay_amt_3 = st.number_input('Amount of bill statement in July, 2005', value=13000)
|
40 |
+
pay_amt_4 = st.number_input('Amount of bill statement in June, 2005', value=14000)
|
41 |
+
pay_amt_5 = st.number_input('Amount of bill statement in May, 2005', value=15000)
|
42 |
+
pay_amt_6 = st.number_input('Amount of bill statement in April, 2005', value=16000)
|
43 |
+
|
44 |
+
# Bikin Submit Button Form
|
45 |
+
submitted = st.form_submit_button()
|
46 |
+
|
47 |
+
data_inf = {
|
48 |
+
'limit_balance' : limit_balance,
|
49 |
+
'sex' : sex,
|
50 |
+
'education_level' : education_level,
|
51 |
+
'marital_status' : marital_status,
|
52 |
+
'age' : age,
|
53 |
+
'pay_1' : pay_1,
|
54 |
+
'pay_2' : pay_2,
|
55 |
+
'pay_3' : pay_3,
|
56 |
+
'pay_4' : pay_4,
|
57 |
+
'pay_5' : pay_5,
|
58 |
+
'pay_6' : pay_6,
|
59 |
+
'bill_amt_1' : bill_amt_1,
|
60 |
+
'bill_amt_2' : bill_amt_2,
|
61 |
+
'bill_amt_3' : bill_amt_3,
|
62 |
+
'bill_amt_4' : bill_amt_4,
|
63 |
+
'bill_amt_5' : bill_amt_5,
|
64 |
+
'bill_amt_6' : bill_amt_6,
|
65 |
+
'pay_amt_1' : pay_amt_1,
|
66 |
+
'pay_amt_2' : pay_amt_2,
|
67 |
+
'pay_amt_3' : pay_amt_3,
|
68 |
+
'pay_amt_4' : pay_amt_4,
|
69 |
+
'pay_amt_5' : pay_amt_5,
|
70 |
+
'pay_amt_6' : pay_amt_6
|
71 |
+
}
|
72 |
+
|
73 |
+
data_inf = pd.DataFrame([data_inf])
|
74 |
+
st.dataframe(data_inf)
|
75 |
+
|
76 |
+
if submitted:
|
77 |
+
|
78 |
+
# Prediksi Model
|
79 |
+
y_pred_inf = best_pipe.predict(data_inf)
|
80 |
+
|
81 |
+
if y_pred_inf == "0":
|
82 |
+
st.write('## Rating : Successfully Paid')
|
83 |
+
else:
|
84 |
+
st.write('## Rating : Failed to pay')
|
85 |
+
|
86 |
+
|
87 |
+
if __name__ == '__main__':
|
88 |
+
run()
|
89 |
+
|
90 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
seaborn
|
4 |
+
numpy
|
5 |
+
matplotlib
|
6 |
+
scipy
|
7 |
+
scikit-learn==1.22
|
8 |
+
Pillow
|
9 |
+
plotly
|