imamzarkasie's picture
Upload 12 files
bc15c43
raw
history blame contribute delete
No virus
4.35 kB
import streamlit as st
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
from PIL import Image
st.set_page_config(
page_title = 'Home Credit Analysis - EDA',
layout = 'wide',
initial_sidebar_state = 'expanded'
)
def run():
# Membuat Title
st.title('Home Credit Analysis')
# Membuat Sub Header
st.subheader('EDA for Home Credit Analysis')
# Menambahkan Gambar
image = Image.open('credit.jpeg')
st.image(image, caption='Home Credit')
# Menambahkan Deskripsi
st.write('This page created by **Imam Zarkasie**')
st.write('### Hello!')
st.write('#### The competition of credit card service is heating up!')
st.write('##### In this page we can explore customer segmentation, more than that this website provides an ability to predict a customer payment risk.')
# Membuat Garis Lurus
st.markdown('---')
# Magic Syntax
'''
On this page, the author will do a simple exploration.
The dataset used is the churn dataset.
'''
# Show DataFrame
df = pd.read_csv('df_subset.csv')
st.dataframe(df)
#Melihat histogram fitur target
# Membuat visualisasi Distribusi Payment
fig, ax =plt.subplots(1,2,figsize=(15,6))
sns.countplot(x='TARGET', data=df, palette="winter", ax=ax[0])
ax[0].set_xlabel("Payment", fontsize= 12)
ax[0].set_ylabel("# of Payment", fontsize= 12)
fig.suptitle('Payment Distribution', fontsize=18, fontweight='bold')
ax[0].set_ylim(0,300000)
ax[0].tick_params(axis='x', rotation=90)
plt.xlabel("Payment", fontsize= 12)
plt.ylabel("# of Payment", fontsize= 12)
for p in ax[0].patches:
ax[0].annotate("%.0f"%(p.get_height()), (p.get_x() + p.get_width() / 2,
p.get_height()+205), ha='center', va='center',fontsize = 11)
df['TARGET'].value_counts().plot(kind='pie',autopct='%1.1f%%', textprops = {"fontsize":12})
ax[1].set_ylabel("% of Payment", fontsize= 12)
st.pyplot(fig)
# Membuat visualisasi Distribusi Contract
fig, ax =plt.subplots(1,2,figsize=(15,6))
sns.countplot(x='NAME_CONTRACT_TYPE', data=df, palette="winter", ax=ax[0])
ax[0].set_xlabel("Contract", fontsize= 12)
ax[0].set_ylabel("# of Contract", fontsize= 12)
fig.suptitle('Contract Distribution', fontsize=18, fontweight='bold')
ax[0].set_ylim(0,300000)
ax[0].tick_params(axis='x', rotation=90)
plt.xlabel("Contract", fontsize= 12)
plt.ylabel("# of Contract", fontsize= 12)
for p in ax[0].patches:
ax[0].annotate("%.0f"%(p.get_height()), (p.get_x() + p.get_width() / 2,
p.get_height()+205), ha='center', va='center',fontsize = 11)
df['NAME_CONTRACT_TYPE'].value_counts().plot(kind='pie',autopct='%1.1f%%', textprops = {"fontsize":12})
ax[1].set_ylabel("% of Contract", fontsize= 12)
plt.show()
# Menampilkan plot di Streamlit
st.pyplot(fig)
# Membuat visualisasi Distribusi Gender
fig, ax =plt.subplots(1,2,figsize=(15,6))
sns.countplot(x='CODE_GENDER', data=df, palette="winter", ax=ax[0])
ax[0].set_xlabel("Gender", fontsize= 12)
ax[0].set_ylabel("# of Gender", fontsize= 12)
fig.suptitle('Gender Distribution', fontsize=18, fontweight='bold')
ax[0].set_ylim(0,300000)
ax[0].tick_params(axis='x', rotation=90)
plt.xlabel("Gender", fontsize= 12)
plt.ylabel("# of Gender", fontsize= 12)
for p in ax[0].patches:
ax[0].annotate("%.0f"%(p.get_height()), (p.get_x() + p.get_width() / 2,
p.get_height()+205), ha='center', va='center',fontsize = 11)
df['CODE_GENDER'].value_counts().plot(kind='pie',autopct='%1.1f%%', textprops = {"fontsize":12})
ax[1].set_ylabel("% of Gender", fontsize= 12)
plt.show()
# Menampilkan plot di Streamlit
st.pyplot(fig)
# Membuat plot scatter
fig, ax = plt.subplots(figsize=(6, 3))
sns.scatterplot(x='AMT_ANNUITY', y='AMT_CREDIT', hue='TARGET', data=df, ax=ax)
# Menambahkan label sumbu dan judul plot
plt.xlabel('AMT_ANNUITY')
plt.ylabel('AMT_CREDIT')
plt.title('Scatter Plot: AMT_ANNUITY vs AMT_CREDIT')
# Menambahkan legenda
plt.legend(title='Target')
# Menampilkan plot di Streamlit
st.pyplot(fig)
if __name__=='__main__':
run()