Gigisghifari's picture
Upload eda.py
de5db35 verified
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
st.set_page_config(
page_title = 'Credit Card Default - EDA',
layout='wide',
initial_sidebar_state='expanded'
)
def run():
# Membuat title
st.title('Model Prediksi Credit Card Default')
# Membuat Subheader
st.subheader('EDA untuk Analisis Dataset Credit Card Default')
# Menambah Gambar
st.image('https://media.istockphoto.com/id/957837328/photo/business-debt-collection-or-recovery-unpaid-invoice.jpg?s=612x612&w=0&k=20&c=7sH7P4t7Fl2PjFfAUOIolZictaF8CsXXsxkbwZBz98g=',
caption= 'Credit Card Default')
# Menambah Deskripsi
st.write('-'*50)
st.write('Graded Challenge 5')
st.write('Nama : Achmad Abdillah Ghifari')
st.write('Batch : BSD-006')
st.write('-'*50)
# menjelaskan kegunaan page ini
st.write('Pada page ini, kita akan melihat exploratory data analyst (EDA) dari dataset credit card default yang dapat dilihat di [BigQuery](https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=ml_datasets&t=credit_card_default&page=table&project=graded-challenge-5&ws=!1m5!1m4!4m3!1sbigquery-public-data!2sml_datasets!3scredit_card_default). dalam exploratory data analysis ini kita akan mencoba menjawab pertanyaan-pertanyaan berikut')
st.write('1. bagaimana distribusi limit balance customer pada data?')
st.write('2. bagaimana persebaran limit balance dan age?')
st.write('3. marital status apa yang memiliki average limit_balance tertinggi?')
st.write('4. apakah lebih banyak customer yang membayar atau melakukan default?')
st.write('5. customer umur berapa yang paling sering melakukan default?')
st.write('6. apa education level terbanyak dari customer kartu kredit?')
st.write('7. berapa limit balance yang paling sering dimiliki kedua gender?')
# membuat garis lurus
st.markdown('---')
# show dataframe
st.write('### Credit Card Default Dataset')
data = pd.read_csv('P1G5_Set_1_A.A_Ghifari(Changed).csv')
st.dataframe(data)
# Membuat Histogram (EDA 1)
st.write('### Histogram of limit balance')
fig = plt.figure(figsize=[15,5])
sns.histplot(data['limit_balance'], kde=True, bins = 30)
st.pyplot(fig)
# Membuat ScatterPlot (EDA 2)
st.write('### Scatterplot of limit balance and age')
fig = plt.figure(figsize=[15,5])
sns.scatterplot(x = 'limit_balance', y = 'age', hue= 'default', data = data)
st.pyplot(fig)
st.write('Keterangan default customer:')
st.write('0 = no (customer tidak melakukan default)')
st.write('1 = yes (customer melakukan default)')
# Membuat barplot (EDA 3)
st.write('### barchart of marital status and limit balance')
fig = plt.figure(figsize=[15,5])
sns.barplot(data=data, x='marital_status', y='limit_balance',)
st.pyplot(fig)
st.write('Keterangan marital status:')
st.write('1 = married')
st.write('2 = single ')
st.write('3 = others')
# Membuat pie chart (EDA 4)
st.write('### pie chart of if a customer has defaulted')
fig = plt.figure(figsize=(15,5))
data['default'].value_counts().plot(kind='pie', autopct='%.2f%%')
st.pyplot(fig)
st.write('Keterangan default customer:')
st.write('0 = no (customer tidak melakukan default)')
st.write('1 = yes (customer melakukan default)')
# Membuat line chart (EDA 5)
st.write('### age of defaulting customer')
Def_Age= data.groupby(['age', 'default']).size().unstack(fill_value=0)
fig, ax = plt.subplots(figsize=[15, 5])
Def_Age.plot(kind='line', ax=ax)
st.pyplot(fig)
st.write('Keterangan default customer:')
st.write('0 = no (customer tidak melakukan default)')
st.write('1 = yes (customer melakukan default)')
# Membuat bar chart (EDA 6)
st.write('### The amount of education level')
fig = plt.figure(figsize=[15,5])
data['education_level'].value_counts().plot(kind='bar')
st.pyplot(fig)
st.write('Keterangan education level:')
st.write('1 = graduate school')
st.write('2 = university')
st.write('3 = high school')
st.write('4 = others')
# Membuat line chart (EDA7)
st.write('### limit balance of gender')
Sex_Bal= data.groupby(['limit_balance', 'sex']).size().unstack(fill_value=0)
fig, ax = plt.subplots(figsize=[15, 5])
Sex_Bal.plot(kind='line', ax=ax)
st.pyplot(fig)
st.write('Keterangan gender/sex:')
st.write('1 = male ')
st.write('2 = female')
if __name__ == '__main__':
run()