File size: 1,814 Bytes
223a0d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e55cbec
223a0d1
 
 
e55cbec
223a0d1
 
 
 
 
 
 
 
e55cbec
 
 
223a0d1
 
e55cbec
 
 
 
 
 
 
223a0d1
 
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
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px

bank_df = pd.read_csv('./csv/BankChurners.csv')
bank_df.drop(columns=["CLIENTNUM", 
                      "Naive_Bayes_Classifier_Attrition_Flag_Card_Category_Contacts_Count_12_mon_Dependent_count_Education_Level_Months_Inactive_12_mon_1",
                      "Naive_Bayes_Classifier_Attrition_Flag_Card_Category_Contacts_Count_12_mon_Dependent_count_Education_Level_Months_Inactive_12_mon_2"], inplace=True)

num_col = bank_df.select_dtypes(include=np.number).columns.tolist()
cat_col = bank_df.select_dtypes(include=object).columns.tolist()
cat_col.remove("Attrition_Flag")

st.set_page_config(
    page_title="Customer Churn Classification",
    layout="wide",
    initial_sidebar_state="expanded",
)

def distribution():
    # distribution plot
    st.header("Data Distribution")
    
    attr_plot('Attrition_Flag')
    
    col1, col2 = st.columns(2)
    
    numerik = col1.selectbox(label="Select Features", options=num_col)
    
    hist_plot(numerik, col1)
    
    kategorik = col2.selectbox(label="Select Features", options=cat_col)
    
    count_plot(kategorik, col2)
    
    st.markdown('''
                
                ''')

def attr_plot(column):
    fig = px.histogram(bank_df, y=column, color="Attrition_Flag", title=f'Distribution of {column}')
    fig.update_layout(width=1200)
    st.plotly_chart(fig, use_container_width=True)

def hist_plot(column, loc):
    fig = px.histogram(bank_df, x=column, color="Attrition_Flag", title=f'Histogram of {column}')
    loc.plotly_chart(fig)

def count_plot(column, loc):
    fig = px.bar(bank_df, y=column, color="Attrition_Flag", title=f'Count Plot of {column}', orientation='h')
    loc.plotly_chart(fig)

if __name__ == "__main__":
    distribution()