Adityaswara
commited on
Commit
•
5da83b1
1
Parent(s):
4bcd4c3
Upload eda.py
Browse files
eda.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import library
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
# library for visualization
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import seaborn as sns
|
9 |
+
import plotly.express as px
|
10 |
+
|
11 |
+
# Function untuk menjalankan streamlit model prediksi
|
12 |
+
def run():
|
13 |
+
# Set the title
|
14 |
+
st.title('Credit Card Client Prediction')
|
15 |
+
|
16 |
+
# Set subheader
|
17 |
+
st.subheader('Halaman ini menampilkan hasil EDA')
|
18 |
+
|
19 |
+
# Upload gambar
|
20 |
+
st.image('https://cdn.britannica.com/02/160902-050-B58BAD84/Credit-cards.jpg')
|
21 |
+
|
22 |
+
# garis horizontal
|
23 |
+
st.write('---')
|
24 |
+
|
25 |
+
# Subjudul
|
26 |
+
st.write('## Dataframe')
|
27 |
+
|
28 |
+
# loading dataset
|
29 |
+
df = pd.read_csv('P1G5_Set_1_muhammad hafidz.csv')
|
30 |
+
|
31 |
+
# menampilkan dataframe
|
32 |
+
st.dataframe(df)
|
33 |
+
st.write('---')
|
34 |
+
|
35 |
+
# Bab Visualisasi
|
36 |
+
st.write('## EDA')
|
37 |
+
|
38 |
+
# Judul visualisasi
|
39 |
+
st.write('### Grafik Tidak Gagal Bayar dan Gaga Bayar')
|
40 |
+
|
41 |
+
# Buat Canvasnya
|
42 |
+
fig = plt.figure(figsize=(15,10))
|
43 |
+
|
44 |
+
ax = sns.countplot(x='default_payment_next_month', hue='default_payment_next_month', data=df)
|
45 |
+
ax.bar_label(ax.containers[0])
|
46 |
+
ax.bar_label(ax.containers[1])
|
47 |
+
plt.legend(['tidak gagal bayar','gagal bayar'])
|
48 |
+
plt.title('Pola tidak gagal bayar dan gagal bayar')
|
49 |
+
plt.show()
|
50 |
+
# syntax streamlit untuk menampilkan grafik
|
51 |
+
st.pyplot(fig)
|
52 |
+
|
53 |
+
|
54 |
+
# Visualisasi ke-dua
|
55 |
+
st.write('### Pola Gender')
|
56 |
+
fig = plt.figure(figsize=(15,10))
|
57 |
+
# Membuat countplot
|
58 |
+
ax = sns.countplot(x='sex', hue='default_payment_next_month', data=df)
|
59 |
+
ax.bar_label(ax.containers[0])
|
60 |
+
ax.bar_label(ax.containers[1])
|
61 |
+
plt.legend(['tidak gagal bayar','gagal bayar'])
|
62 |
+
plt.title('Pola gender tidak gagal bayar dan gagal bayar')
|
63 |
+
plt.xlabel('Gender')
|
64 |
+
plt.ylabel('Count')
|
65 |
+
plt.show()
|
66 |
+
st.pyplot(fig)
|
67 |
+
|
68 |
+
|
69 |
+
# Visualisasi ke-dua
|
70 |
+
st.write('### Pola Pendidikan')
|
71 |
+
fig = plt.figure(figsize=(15,10))
|
72 |
+
# Membuat countplot
|
73 |
+
ax = sns.countplot(x='education_level', hue='default_payment_next_month', data=df)
|
74 |
+
plt.title('Countplot Distribusi Data dengan 2 Kolom')
|
75 |
+
ax.bar_label(ax.containers[0])
|
76 |
+
ax.bar_label(ax.containers[1])
|
77 |
+
plt.legend(['tidak gagal bayar','gagal bayar'])
|
78 |
+
plt.title('Pendidikan tidak gagal bayar dan gagal bayar')
|
79 |
+
plt.xlabel('Pendidikan')
|
80 |
+
plt.ylabel('Count')
|
81 |
+
plt.show()
|
82 |
+
st.pyplot(fig)
|
83 |
+
|
84 |
+
|
85 |
+
# Visualisasi ke-dua
|
86 |
+
st.write('### Pola Status')
|
87 |
+
fig = plt.figure(figsize=(15,10))
|
88 |
+
# Membuat countplot
|
89 |
+
ax1 = sns.countplot(x='marital_status', hue='default_payment_next_month', data=df)
|
90 |
+
plt.title('Countplot Distribusi Data dengan 2 Kolom')
|
91 |
+
ax1.bar_label(ax1.containers[0])
|
92 |
+
ax1.bar_label(ax1.containers[1])
|
93 |
+
plt.legend(['tidak gagal bayar','gagal bayar'])
|
94 |
+
plt.title('Status pernikahan tidak gagal bayar dan gagal bayar')
|
95 |
+
plt.xlabel('Status pernikahan')
|
96 |
+
plt.ylabel('Count')
|
97 |
+
plt.show()
|
98 |
+
st.pyplot(fig)
|
99 |
+
|
100 |
+
|
101 |
+
st.write('---')
|
102 |
+
st.write('Create by Muhammad Hafidz Adityaswara')
|
103 |
+
|
104 |
+
# Menjalankan perintah setelah halaman terbuka
|
105 |
+
if __name__ == "__main__":
|
106 |
+
run()
|