replica-m1-p2 / eda.py
mukhlishr's picture
Update eda.py
3b6b3df
raw
history blame contribute delete
No virus
3.57 kB
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 Prediction')
# 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, ... 6 >= 51)')
bins = [-1, 10,20,30,40,50,100]
labels =[1,2,3,4,5,6]
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()