Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- EDA.py +70 -0
- Prediction.py +53 -0
- app.py +9 -0
EDA.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Set page config
|
9 |
+
st.set_page_config(
|
10 |
+
page_title= 'Credit_Card_Default_EDA',
|
11 |
+
layout= 'wide',
|
12 |
+
initial_sidebar_state= 'expanded'
|
13 |
+
)
|
14 |
+
|
15 |
+
# Create Function for EDA
|
16 |
+
def run():
|
17 |
+
#Create title
|
18 |
+
st.title('CREDIT CARD CUSTOMER')
|
19 |
+
|
20 |
+
# Create Sub Header atau Sub Judul
|
21 |
+
st.subheader('EDA untuk Analisis Dataset Credit Card Default')
|
22 |
+
|
23 |
+
# Add Image
|
24 |
+
st.image('https://www.cimbniaga.co.id/content/dam/cimb/inspirasi/Apa-Itu-Kartu-Kredit-Seperti-Apa-Memanfaatkannya.webp', caption= 'Credit Card Customer')
|
25 |
+
|
26 |
+
# Create a Description
|
27 |
+
st.write('Page Made by Allen')
|
28 |
+
|
29 |
+
|
30 |
+
# Magic Syntax
|
31 |
+
'''
|
32 |
+
Pada page kali ini, penulis akan melakukan eksplorasi sederhana,
|
33 |
+
Dataset yang digunakan adalah Credit Card Default.
|
34 |
+
Dataset ini berasal dari Big Query Google
|
35 |
+
|
36 |
+
'''
|
37 |
+
|
38 |
+
# Create Straight Line
|
39 |
+
st.markdown('---')
|
40 |
+
|
41 |
+
# Show Dataframe
|
42 |
+
df = pd.read_csv('P1G5_Set_1_Allen.csv')
|
43 |
+
st.dataframe(df)
|
44 |
+
|
45 |
+
# Create BarPlot
|
46 |
+
st.write('### Plotly Plot - Education Level vs Credit')
|
47 |
+
fig= px.bar(df, x= 'education_level', y= 'default_payment_next_month',
|
48 |
+
hover_data=['education_level','default_payment_next_month'])
|
49 |
+
st.plotly_chart(fig)
|
50 |
+
|
51 |
+
# Statement menggunakan st.write
|
52 |
+
st.write('Dari data diatas kita mendapatkan informasi mengenai tingkat pendidikan yang berpengaruh pada pembayaran utang dan mempengaruhi limit balance, semakin rendah pendidikan ternyata mempengaruhi tingkat utang')
|
53 |
+
|
54 |
+
|
55 |
+
st.write('### Plotly Plot - Umur vs Credit')
|
56 |
+
fig= px.bar(df, x= 'age', y= 'default_payment_next_month',
|
57 |
+
hover_data=['age','default_payment_next_month'])
|
58 |
+
st.plotly_chart(fig)
|
59 |
+
|
60 |
+
# Statement menggunakan st.write
|
61 |
+
st.write('Dari data diatas kita mendapatkan informasi bahwa customer yang paling banyak melakukan credit berada pada usia 30-40 tahun yaitu dimana ada pada usia kerja atau usia produktif')
|
62 |
+
|
63 |
+
#Membuktikan umur paling banyak ada pada umur 30
|
64 |
+
st.write('### Plot age')
|
65 |
+
fig= plt.figure(figsize=(20,5))
|
66 |
+
sns.countplot(x='age', data=df)
|
67 |
+
st.pyplot(fig)
|
68 |
+
st.write('Umur 30 paling banyak melakukan credit customer')
|
69 |
+
if __name__ == '__main__':
|
70 |
+
run()
|
Prediction.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import json
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
# Load All Files
|
8 |
+
with open('best_param.pkl', 'rb') as file_1:
|
9 |
+
best_params = pickle.load(file_1)
|
10 |
+
|
11 |
+
with open('preprocessing_pipeline.pkl', 'rb') as file_2:
|
12 |
+
preprocessing_pipeline= pickle.load(file_2)
|
13 |
+
|
14 |
+
def run ():
|
15 |
+
with st.form(key ='Credit FORM'): #Nulis nama sendiri menggunakan name= st.text_input('')
|
16 |
+
education_level= st.radio('Select Education_level', options=['1','2','3','4','5','6'])
|
17 |
+
sex = st.radio(
|
18 |
+
'Select gender',
|
19 |
+
options=['male','female'])
|
20 |
+
limit_balance= st.text_input('limit_balance', value= 'None')
|
21 |
+
st.markdown('---')
|
22 |
+
pay_0= st.slider('pay_0', min_value=-2,max_value=2,)
|
23 |
+
pay_2= st.slider('pay_2', min_value=-2,max_value=2,)
|
24 |
+
pay_3= st.slider('pay_3', min_value=-2,max_value=2,)
|
25 |
+
pay_4= st.slider('pay_4', min_value=-2,max_value=2,)
|
26 |
+
pay_5= st.slider('pay_5', min_value=-2,max_value=2,)
|
27 |
+
pay_6= st.slider('pay_6', min_value=-2,max_value=2,)
|
28 |
+
|
29 |
+
submitted = st.form_submit_button('Predict')
|
30 |
+
|
31 |
+
# Create New Data
|
32 |
+
df_inf={
|
33 |
+
'limit_balance': limit_balance,
|
34 |
+
'sex': sex,
|
35 |
+
'education_level': education_level ,
|
36 |
+
'pay_0': pay_0 ,
|
37 |
+
'pay_2': pay_2,
|
38 |
+
'pay_3': pay_3,
|
39 |
+
'pay_4': pay_4,
|
40 |
+
'pay_5': pay_5,
|
41 |
+
'pay_6': pay_6,
|
42 |
+
}
|
43 |
+
df_inf = pd.DataFrame([df_inf])
|
44 |
+
|
45 |
+
if submitted:
|
46 |
+
df_inf_best_params = df_inf[best_params]
|
47 |
+
df_inf_classifier= df_inf[preprocessing_pipeline]
|
48 |
+
df_inf_final = np.concatenate([preprocessing_pipeline], axis=1)
|
49 |
+
y_pred_inf = best_params.predict(df_inf_final)
|
50 |
+
st.write(f'# Rating {best_params}:', int(y_pred_inf))
|
51 |
+
|
52 |
+
if best_params == '__main__':
|
53 |
+
run()
|
app.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import EDA
|
3 |
+
import Prediction
|
4 |
+
|
5 |
+
Navigation = st.sidebar.selectbox('Pilih Halaman:', ('EDA','Predict Credit Card Customer'))
|
6 |
+
if Navigation == 'EDA':
|
7 |
+
EDA.run()
|
8 |
+
else:
|
9 |
+
Prediction.run()
|