File size: 4,354 Bytes
bc15c43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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()