File size: 3,562 Bytes
7a7058d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a794f4
7a7058d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
from PIL import Image


st.set_page_config(
    page_title = 'Churn Condition',
    layout = 'wide',
    initial_sidebar_state='expanded'
)

def run():

    # title
    st.title( 'Churn Customer')

    # sub header
    st.subheader('Churn or Not Churn')

    # insert image
    image = Image.open('2.jpg')
    st.image(image, caption='image from project pro, education purpose only')

    # Deskripsi
    st.write('Exploratory Data from Churn dataset')

    # show data frame
    st.write('The first 10 Data')
    df = pd.read_csv('https://raw.githubusercontent.com/mukhlishr/rasyidi/main/churn.csv')
    st.dataframe(df.head(10))

    # Barplot target columns 
    st.write('###### Churn condition ')
    st.write('###### Churn = 1 ; Not Churn = 0 ')
    fig=plt.figure(figsize=(15,5))
    sns.countplot(x='churn_risk_score', data = df)
    st.pyplot(fig)

   # Barplot avg transaction value 
    st.write('###### Avg Transaction Value by Customer churn')
    a=df[df['churn_risk_score']==1]['avg_transaction_value']
    fig=plt.figure(figsize=(15,5))
    sns.barplot(x=a.index, y=a)
    st.pyplot(fig)

    # Barplot frequency login
    st.write('###### Avg Frequency login (1 = 1-10, 2 = 11-20, ... 7 >= 51)')
    bins = [-1, 10,20,30,40,50,100]
    labels =[1,2,3,4,5,6,7]
    df['binned_frequency_login'] = pd.cut(df['avg_frequency_login_days'], bins,labels=labels).astype(float)
    fig=plt.figure(figsize=(15,5))
    sns.countplot(x='binned_frequency_login', data = df)
    st.pyplot(fig)

    # Pieplot membership
    st.write('###### Membership')
    data = df['membership_category'].value_counts()
    keys = df['membership_category'].value_counts().index
    palette_color = sns.color_palette('bright')
    fig=plt.figure(figsize=(15,5))
    plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
    plt.title('Pieplot')
    st.pyplot(fig)    

    # Pieplot joined through referral 
    st.write('###### joined through referral')
    data = df['joined_through_referral'].value_counts()
    keys = df['joined_through_referral'].value_counts().index
    palette_color = sns.color_palette('bright')
    fig=plt.figure(figsize=(15,5))
    plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
    plt.title('Pieplot')
    st.pyplot(fig)    

    # Pieplot preferred_offer_types 
    st.write('###### preferred offer types')
    data = df['preferred_offer_types'].value_counts()
    keys = df['preferred_offer_types'].value_counts().index
    palette_color = sns.color_palette('bright')
    fig=plt.figure(figsize=(15,5))
    plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
    plt.title('Pieplot')
    st.pyplot(fig)    

    # Pieplot past_complaint 
    st.write('###### past complaint')
    data = df['past_complaint'].value_counts()
    keys = df['past_complaint'].value_counts().index
    palette_color = sns.color_palette('bright')
    fig=plt.figure(figsize=(15,5))
    plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
    plt.title('Pieplot')
    st.pyplot(fig)        

    # Pieplot feedback 
    st.write('###### feedback ')
    data = df['feedback'].value_counts()
    keys = df['feedback'].value_counts().index
    palette_color = sns.color_palette('bright')
    fig=plt.figure(figsize=(15,5))
    plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
    plt.title('Pieplot')
    st.pyplot(fig)       

if __name__ == '__main__':
    run()