nursakinahbadriah
commited on
Commit
•
1ab3717
1
Parent(s):
8caedde
Upload 5 files
Browse files- app.py +23 -0
- eda.py +60 -0
- prediction.py +119 -0
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
import eda
|
4 |
+
import prediction
|
5 |
+
|
6 |
+
# setting page configuration
|
7 |
+
# st.set_page_config(page_title= 'FIFA 2022 Data',
|
8 |
+
# page_icon= ':bar_chart:',
|
9 |
+
# layout= 'wide',
|
10 |
+
# initial_sidebar_state='auto')
|
11 |
+
|
12 |
+
navigation = st.sidebar.selectbox("Select Page",
|
13 |
+
options=['EDA', 'Predict'])
|
14 |
+
st.sidebar.write('# About')
|
15 |
+
st.sidebar.write('''
|
16 |
+
This page is created to predict credit card default data
|
17 |
+
''')
|
18 |
+
|
19 |
+
|
20 |
+
if navigation == 'EDA':
|
21 |
+
eda.run()
|
22 |
+
else:
|
23 |
+
prediction.run()
|
eda.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# streamlit
|
2 |
+
import streamlit as st
|
3 |
+
# pandas
|
4 |
+
import pandas as pd
|
5 |
+
# visualisasi
|
6 |
+
import seaborn as sns
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import plotly.express as px
|
9 |
+
from PIL import Image
|
10 |
+
|
11 |
+
st.set_page_config(
|
12 |
+
page_title = 'Predict Credit Card Default',
|
13 |
+
layout = 'wide',
|
14 |
+
initial_sidebar_state='expanded'
|
15 |
+
)
|
16 |
+
|
17 |
+
def run():
|
18 |
+
|
19 |
+
st.title('Predict Credit Card')
|
20 |
+
|
21 |
+
st.subheader('EDA untuk analisis dataset default credit card')
|
22 |
+
|
23 |
+
st.image('https://image.cermati.com/v1536918930/kcqxfjxwseh5e6kyrrpv.jpg',
|
24 |
+
caption= 'CREDIT CARD')
|
25 |
+
|
26 |
+
st.write('This page is made by badriahnursakinah')
|
27 |
+
st.write('# Hello')
|
28 |
+
|
29 |
+
st.markdown('---')
|
30 |
+
|
31 |
+
'''
|
32 |
+
Pada page kali ini, penulis akan melakukan
|
33 |
+
eksplorasi sederhana untuk memprediksi kemungkinan default pada pembayaran kartu kredit
|
34 |
+
Dataset yg digunakan adalah dataset predict default payment next month
|
35 |
+
Dataset ini berasal dari website Big Query
|
36 |
+
'''
|
37 |
+
|
38 |
+
data = pd.read_csv('P1G5_Set_1_badriah_nursakinah.csv')
|
39 |
+
st.dataframe(data)
|
40 |
+
|
41 |
+
st.write('#### Plot education_level')
|
42 |
+
fig = plt.figure(figsize=(15,5))
|
43 |
+
sns.countplot(x='education_level', data= data)
|
44 |
+
st.pyplot(fig)
|
45 |
+
|
46 |
+
st.write('### Histogram')
|
47 |
+
options = st.selectbox('Pilih kolom:',
|
48 |
+
('sex',
|
49 |
+
'education_level', 'marital_status',
|
50 |
+
'age'))
|
51 |
+
fig = plt.figure(figsize=(15,5))
|
52 |
+
sns.histplot(data[options], bins=30,kde=True)
|
53 |
+
st.pyplot(fig)
|
54 |
+
|
55 |
+
st.write('#### Plotly Plot - limit_balance dengan Overall')
|
56 |
+
fig = px.scatter(data,x='limit_balance',y='default_payment_next_month', hover_data=['pay_0','pay_2','pay_3','pay_4','pay_5','pay_6',])
|
57 |
+
st.plotly_chart(fig)
|
58 |
+
|
59 |
+
if __name__ == '__main__':
|
60 |
+
run()
|
prediction.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
import pandas as pd
|
7 |
+
import numpy as np
|
8 |
+
import pickle
|
9 |
+
import json
|
10 |
+
|
11 |
+
# Load the pre-trained model using pickle
|
12 |
+
with open('best_svm_model.pkl', 'rb') as file_1:
|
13 |
+
model = pickle.load(file_1)
|
14 |
+
|
15 |
+
# Create a Streamlit web app
|
16 |
+
def run():
|
17 |
+
st.title("Credit Card Default Prediction Dashboard")
|
18 |
+
|
19 |
+
# Add input fields for user input
|
20 |
+
st.header("User Input Features")
|
21 |
+
|
22 |
+
with st.form('predict player'):
|
23 |
+
st.title('Playernya aja')
|
24 |
+
|
25 |
+
# Input fields for each feature
|
26 |
+
limit_balance = st.slider("LIMIT_BAL (Amount of Credit in NT dollars)", 0, 1000000, 50000)
|
27 |
+
sex = st.radio("SEX (Gender)", ["Male", "Female"])
|
28 |
+
education = st.radio("EDUCATION (Education Level)", ["Graduate School", "University", "High School", "Others"])
|
29 |
+
marriage = st.radio("MARRIAGE (Marital Status)", ["Married", "Single", "Others"])
|
30 |
+
age = st.slider("AGE (Age in years)", 20, 80, 30)
|
31 |
+
st.write('Payment Status')
|
32 |
+
st.write("-1 : Sudah Dibayar Sebelum H-1")
|
33 |
+
st.write("-2 : Sudah Dibayar Sebelum H-2")
|
34 |
+
st.write("0 : Dibayar Tepat Waktu")
|
35 |
+
st.write("2 : Telat Pembayaran 2 Bulan")
|
36 |
+
st.write("3 : Telat Pembayaran 3 Bulan")
|
37 |
+
st.write("4 : Telat Pembayaran 4 Bulan")
|
38 |
+
st.write("5 : Telat Pembayaran 5 Bulan")
|
39 |
+
st.write("6 : Telat Pembayaran 6 Bulan")
|
40 |
+
pay_status_sept = st.slider("PAY_0 (Repayment status in September, 2005)", -2, 8, 0)
|
41 |
+
pay_status_aug = st.slider("PAY_2 (Repayment status in August, 2005)", -2, 8, 0)
|
42 |
+
pay_status_jul = st.slider("PAY_3 (Repayment status in July, 2005)", -2, 8, 0)
|
43 |
+
pay_status_jun = st.slider("PAY_4 (Repayment status in June, 2005)", -2, 8, 0)
|
44 |
+
pay_status_may = st.slider("PAY_5 (Repayment status in May, 2005)", -2, 8, 0)
|
45 |
+
pay_status_apr = st.slider("PAY_6 (Repayment status in April, 2005)", -2, 8, 0)
|
46 |
+
bill_amt_sept = st.slider("BILL_AMT1 (Bill statement in September, 2005 - NT dollar)", 0, 1000000, 5000)
|
47 |
+
bill_amt_aug = st.slider("BILL_AMT2 (Bill statement in August, 2005 - NT dollar)", 0, 1000000, 5000)
|
48 |
+
bill_amt_jul = st.slider("BILL_AMT3 (Bill statement in July, 2005 - NT dollar)", 0, 1000000, 5000)
|
49 |
+
bill_amt_jun = st.slider("BILL_AMT4 (Bill statement in June, 2005 - NT dollar)", 0, 1000000, 5000)
|
50 |
+
bill_amt_may = st.slider("BILL_AMT5 (Bill statement in May, 2005 - NT dollar)", 0, 1000000, 5000)
|
51 |
+
bill_amt_apr = st.slider("BILL_AMT6 (Bill statement in April, 2005 - NT dollar)", 0, 1000000, 5000)
|
52 |
+
pay_amt_sept = st.slider("PAY_AMT1 (Previous payment in September, 2005 - NT dollar)", 0, 100000, 500)
|
53 |
+
pay_amt_aug = st.slider("PAY_AMT2 (Previous payment in August, 2005 - NT dollar)", 0, 100000, 500)
|
54 |
+
pay_amt_jul = st.slider("PAY_AMT3 (Previous payment in July, 2005 - NT dollar)", 0, 100000, 500)
|
55 |
+
pay_amt_jun = st.slider("PAY_AMT4 (Previous payment in June, 2005 - NT dollar)", 0, 100000, 500)
|
56 |
+
pay_amt_may = st.slider("PAY_AMT5 (Previous payment in May, 2005 - NT dollar)", 0, 100000, 500)
|
57 |
+
pay_amt_apr = st.slider("PAY_AMT6 (Previous payment in April, 2005 - NT dollar)", 0, 100000, 500)
|
58 |
+
|
59 |
+
submit = st.form_submit_button("Predict Player Rating")
|
60 |
+
|
61 |
+
# Define mappings for education and marriage
|
62 |
+
education_mapping = {
|
63 |
+
"Graduate School": 1,
|
64 |
+
"University": 2,
|
65 |
+
"High School": 3,
|
66 |
+
"Others": 4
|
67 |
+
}
|
68 |
+
|
69 |
+
marriage_mapping = {
|
70 |
+
"Married": 1,
|
71 |
+
"Single": 2,
|
72 |
+
"Others": 3
|
73 |
+
}
|
74 |
+
|
75 |
+
# Create a DataFrame with user input data
|
76 |
+
user_input_data = pd.DataFrame({
|
77 |
+
"limit_balance": [limit_balance],
|
78 |
+
"sex": [1 if sex == "Male" else 2], # Map 'Male' to 1 and 'Female' to 2
|
79 |
+
"education_level": [education_mapping[education]],
|
80 |
+
"marital_status": [marriage_mapping[marriage]],
|
81 |
+
"age": [age],
|
82 |
+
"pay_1": [pay_status_sept],
|
83 |
+
"pay_2": [pay_status_aug],
|
84 |
+
"pay_3": [pay_status_jul],
|
85 |
+
"pay_4": [pay_status_jun],
|
86 |
+
"pay_5": [pay_status_may],
|
87 |
+
"pay_6": [pay_status_apr],
|
88 |
+
"bill_amt_1": [bill_amt_sept],
|
89 |
+
"bill_amt_2": [bill_amt_aug],
|
90 |
+
"bill_amt_3": [bill_amt_jul],
|
91 |
+
"bill_amt_4": [bill_amt_jun],
|
92 |
+
"bill_amt_5": [bill_amt_may],
|
93 |
+
"bill_amt_6": [bill_amt_apr],
|
94 |
+
"pay_amt_1": [pay_amt_sept],
|
95 |
+
"pay_amt_2": [pay_amt_aug],
|
96 |
+
"pay_amt_3": [pay_amt_jul],
|
97 |
+
"pay_amt_4": [pay_amt_jun],
|
98 |
+
"pay_amt_5": [pay_amt_may],
|
99 |
+
"pay_amt_6": [pay_amt_apr]
|
100 |
+
})
|
101 |
+
|
102 |
+
# Predict button
|
103 |
+
if submit:
|
104 |
+
# Make predictions using the loaded model
|
105 |
+
predicted_default = model.predict(user_input_data)
|
106 |
+
|
107 |
+
# Display the prediction result
|
108 |
+
st.subheader("Prediction Result")
|
109 |
+
if predicted_default[0] == 1:
|
110 |
+
st.write("The model predicts that the client may default on their credit card payment.")
|
111 |
+
else:
|
112 |
+
st.write("The model predicts that the client is unlikely to default on their credit card payment.")
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
#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,default_payment_next_month,Klasifikasi
|
119 |
+
#0,240000.0,2,2,1,41.0,1.0,-1.0,-1.0,-1.0,-1,-1,0.0,40529.0,3211.0,9795.0,11756.0,12522.0,40529.0,3211.0,9795.0,11756.0,12522.0,6199.0,0,Dewasa
|