Repository navigation
Expand file tree
/
Copy pathchurncharts.py
More file actions
55 lines (43 loc) · 1.94 KB
/
Copy pathchurncharts.py
File metadata and controls
55 lines (43 loc) · 1.94 KB
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
"""
This script generates charts for the Course 1 Deck using the churndata files
"""
import pandas as pd, matplotlib.pyplot as plt, os, sys, seaborn as sns
os.getcwd()
# IBM colors
from colorsetup import coloribm, colors, palette
sns.set_palette(palette)
from datasetup import labels, churndata
# Start with subset of phone customers
df_phone = churndata[churndata.phone=='Yes']
# Look at churn value assigned by payment type
sns.barplot(y='churn_value', x='payment', data=df_phone, ci=None)
plt.ylabel('Churn Rate')
plt.xlabel('Payment Type')
plt.title('Churn Rate by Payment Type, Phone Customers')
plt.savefig('churn_pay_type.png')
sns.barplot(y='churn_value', x='contract', data=df_phone, ci=None)
plt.ylabel('Churn Rate')
plt.xlabel('Contract Type')
plt.title('Churn Rate by Contract Type, Phone Customers')
plt.savefig('churn_contract_type.png')
sns.barplot(y='churn_value', x=pd.cut(df_phone.months, bins=5), data=df_phone, ci=None)
plt.ylabel('Churn Rate')
plt.xlabel('Tenure Range in Months')
plt.title('Churn Rate by Tenure, Phone Customers')
plt.savefig('churn_tenure.png')
dfr = df_phone.rename(columns=labels)
#df_phone.info()
sns.jointplot(x=dfr[labels['months']], y=dfr[labels['monthly']], kind='hex')
#plt.xlabel('Tenure in Months')
#plt.ylabel('Average Monthly Payment')
#plt.title('Hexbin Plot of Tenure and Payment')
plt.savefig('hexbin_tenure_pmt.png')
df_phone_pairplot = df_phone[['months', 'gb_mon', 'total_revenue', 'cltv', 'churn_value']].rename(columns=labels)
sns.pairplot(df_phone_pairplot, vars=list(df_phone_pairplot.columns[:4]), hue=labels['churn_value'])
#df_phone_pairplot = df_phone[['months', 'gb_mon', 'total_revenue', 'cltv', 'churn_value']]
#sns.pairplot(df_phone_pairplot.rename(columns=labels), vars=['months', 'gb_mon', 'total_revenue', 'cltv'], hue=labels['churn_value'])
plt.savefig('phone_pairplot.png')
df_phone.groupby('churn_value')['total_revenue'].hist()
df_phone.groupby('churn_value')['cltv'].hist()
#######
#breakpoint()