<jupyter_start><jupyter_text>PROJECT-BI Churn  Customer Churn AnalysisContextThe leading telecom company has a massive market share but one big problem: several rivals that are constantly trying to steal customers.  Because this company has been the market leader for so many years, there are not significant opportunities to grow with new customers.  Instead, company executives have decided to focus on their churn: the rate at which they lose customers.They have two teams especially interested in this data: the marketing team and the customer service team.  Each team has its own reason for wanting the analysis. The marketing team wants to find out who the most likely people to churn are and create content that suits their interests.  The customer service team would like to proactively reach out to customers who are about to churn, and try to encourage them to stay.They decide to hire you for two tasks:Help them identify the types of customers who churnPredict who of their current customers will churn next monthTo do this, they offer you a file of 7,000 customers. Each row is a customer.  The Churn column will say Yes if the customer churned in the past month.  The data also offers demographic data and data on the services that each customer purchases.  Finally there is information on the payments those customers make.Deliverables - What is expected Week 1A presentation explaining churn for the marketing team - with links to technical aspects of your work. Tell a story to the marketing team to help them understand the customers who churn and what the marketing team can do to prevent it.  Highlight the information with helpful visualizations.How much is churn affecting the business? How big is churn compared to the existing customer base?Explain churn by the below categories. Are there any factors that combine to be especially impactful?Customer demographics like age and genderServices usedBilling informationWhat services are typically purchased by customers who churned? Are any services especially helpful in retaining customers?Bonus! How long will it take for the company to lose all its customers?  Which demographics will they lose first?  Data Data Preprocessing<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression
import warnings
warnings.filterwarnings("ignore")
url="Dataset/datasets_13996_18858_WA_Fn-UseC_-Telco-Customer-Churn (2).csv"
df_bi = pd.read_csv(url)

df_bi.shape
df_bi.head()
df_bi.describe()
df_bi.dtypes
df_bi['TotalCharges'] = pd.to_numeric(df_bi['TotalCharges'],errors='coerce')
df_bi.dtypes
df_bi.isnull().sum()
df_bi['TotalCharges'].dropna(inplace=True,axis=0)
df_bi.info()
df_bi.mean()
df_bi.boxplot()<jupyter_output><empty_output><jupyter_text>1.  The churn of the customer  affect the business cause there's 1869 of customers are churn Here you can see how many customers who have churned  We can see that there are about 5174 people who who have not Churn<jupyter_code>#let's count the number of people churn or not
data_churn = df_bi['Churn']
data_count = data_churn.value_counts()
data_f = data_count.to_frame()
data_f<jupyter_output><empty_output><jupyter_text>How big is churn compared to the existing customer base?  Let's see  what percentage of clients are Churn or Not<jupyter_code># How much is churn affecting the business
# Data to plot
sizes = df_bi['Churn'].value_counts(sort = True)
colors = ["#BDFCC9","grey"] 
explode = (0.1,0.1)
labels= ['No','Yes']
# Plot
plt.pie(sizes,colors=colors,labels=labels,explode=explode,autopct='%1.1f%%',startangle=270,)
plt.title('Percentage of Churn ')
plt.show()<jupyter_output><empty_output><jupyter_text>The amount of churn customers is 26.5% and 73.5% are still our customers  2. Explain churn by the below categories.<jupyter_code>age_gender= df_bi.groupby(['SeniorCitizen','gender','Churn']).size().to_frame()
age_gender<jupyter_output><empty_output><jupyter_text>Here we can see how many men are churn and we can see the men who churn and those who don't, including the women.  Here we can see the customers who Churn by age at the next you'll see the chart<jupyter_code>df_bi[['SeniorCitizen','Churn']].groupby(['Churn','SeniorCitizen']).size()/df_bi.Churn.count()<jupyter_output><empty_output><jupyter_text>Customer demographics like age and gender  Customer who Churn and who don't Churn by Gender<jupyter_code>ax = sns.countplot(x="gender", hue="Churn", data=df_bi)
ax.set_title("Customer demographics Churn by gender")

sizes = df_bi['gender'].value_counts(sort = True)
colors = ["#BDFCC9","grey"] 
explode = (0.1,0.1)
labels= ['No','Yes']
# Plot
plt.pie(sizes,colors=colors,labels=labels,explode=explode,autopct='%1.1f%%',startangle=270,)
plt.title('Percentage of Churn by gender')
plt.show()<jupyter_output><empty_output><jupyter_text>Customer who Churn and who don't Churn by Age<jupyter_code>ax = sns.countplot(x="SeniorCitizen", hue="Churn", data=df_bi)
ax.set_title("Customer demographics Churn by age")<jupyter_output><empty_output><jupyter_text>We gouping all our Service<jupyter_code>services= df_bi.groupby(['PhoneService','MultipleLines','InternetService','OnlineSecurity','DeviceProtection','TechSupport','StreamingTV','StreamingMovies','PaperlessBilling','PaymentMethod','Churn']).size().to_frame()
services<jupyter_output><empty_output><jupyter_text>Services used by Customers who's Churn and who's not Churn  Count all customers who's Churn or not  use PhoneService<jupyter_code>ax = sns.countplot(x="PhoneService", hue="Churn", data=df_bi)
ax.set_title("Customer demographics Churn by PhoneService ")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use InternetService<jupyter_code>ax = sns.countplot(x="InternetService", hue="Churn", data=df_bi)
ax.set_title("Customer demographics  InternetService in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use StreamingTV<jupyter_code>ax = sns.countplot(x="StreamingTV", hue="Churn", data=df_bi)
ax.set_title("Customer demographics StreamingTV in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use StreamingMovies<jupyter_code>ax = sns.countplot(x="StreamingMovies", hue="Churn", data=df_bi)
ax.set_title("Customer demographics StreamingMovies in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use OnlineSecurity<jupyter_code>ax = sns.countplot(x="OnlineSecurity", hue="Churn", data=df_bi)
ax.set_title("Customer demographics  OnlineSecurity in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use OnlineBackup<jupyter_code>ax = sns.countplot(x="OnlineBackup", hue="Churn", data=df_bi)
ax.set_title("Customer demographics OnlineBackup in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use TechSupport<jupyter_code>ax = sns.countplot(x="TechSupport", hue="Churn", data=df_bi)
ax.set_title("Customer demographics  TechSupport in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use MultipleLines<jupyter_code>ax = sns.countplot(x="MultipleLines", hue="Churn", data=df_bi)
ax.set_title("Customer demographics MultipleLines in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Count all customers who's Churn or not  use DeviceProtection<jupyter_code>ax = sns.countplot(x="DeviceProtection", hue="Churn", data=df_bi)
ax.set_title("Customer demographics  DeviceProtection in relation to Churn or not Churn")<jupyter_output><empty_output><jupyter_text>Billing information The Churn Billing the compagny let's see by the information that we received by the company<jupyter_code>df_bi['MonthlyCharges'].describe().to_frame()
df_bi['PaymentMethod'].describe().to_frame()<jupyter_output><empty_output><jupyter_text>We can see that the customer<jupyter_code>ax = sns.countplot(x="PaymentMethod", hue="Churn", data=df_bi)
ax.set_title("Customer demographics Churn by PaymentMethod ")
ax = sns.countplot(x="PaperlessBilling", hue="Churn", data=df_bi)
ax.set_title("Customer demographics Churn by PaperlessBilling ")
df_bi['MonthlyCharges'].plot(kind='hist', figsize=(8, 5))

plt.title('Billing information Churn by MonthlyChargegs') # add a title to the histogram
plt.ylabel('Churn') # add y-label
plt.xlabel('MonthlyCharges') # add x-label

plt.show()
df_bi['tenure'].describe().to_frame()
df_bi['TotalCharges'].plot(kind='hist', figsize=(8, 5))

plt.title('Billing information Churn by TotalCharges') # add a title to the histogram
plt.ylabel('Churn') # add y-label
plt.xlabel('TotalCharges') # add x-label

plt.show()
df_bi['tenure'].plot(kind='hist', figsize=(8, 5))

plt.title('Billing information Churn by Tenure') # add a title to the histogram
plt.ylabel('Churn') # add y-label
plt.xlabel('tenure') # add x-label

plt.show()
df_bi['TotalCharges'].describe().to_frame()
df_bi['TotalCharges'].plot(kind='hist', figsize=(8, 5))

plt.title('Billing information Churn by TotalCharges') # add a title to the histogram
plt.ylabel('Churn') # add y-label
plt.xlabel('TotalCharges') # add x-label

plt.show()<jupyter_output><empty_output><jupyter_text>df_plot = df_bi.groupby('tenure').Churn.mean().reset_index()plot_data_bi = [    go.Scatter(        x=df_plot['tenure'],        y=df_plot['Churn'],        mode='markers',        name='Low',        marker= dict(size= 7,            line= dict(width=1),            color= 'blue',            opacity= 0.8           ))]plot_layout = go.Layout(        yaxis= {'title': "Churn Rate"},        xaxis= {'title': "Tenure"},        title='Tenure based Churn rate',        plot_bgcolor  = "rgb(243,243,243)",        paper_bgcolor  = "rgb(243,243,243)")fig = go.Figure(data=plot_data_bi, layout=plot_layout)pyoff.iplot(fig)  3.  Services are typically purchased by customers who churned<jupyter_code>df_bi_churn=df_bi.Churn.replace(to_replace = {'Yes' == 1, 'No' == 0}, inplace = True)
cols = df_bi.columns
cols = list(cols)
display(cols)
services_1= df_bi.groupby('Churn').mean()
services_1
val = df_bi[df_bi.Churn=='Yes']
val
plt.figure(figsize = (10,3))
sns.heatmap(val.corr(),annot =True, linewidth = 0.5,cmap ='RdBu_r')
plt.show()
services_1= df_bi.groupby('Churn').mean()
services_1
val = df_bi[df_bi.Churn=='Yes']
val

sizes = val['gender'].value_counts(sort = True)
print(sizes)
colors = ["#BDFCC9","grey"] 
explode = (0.1,0.1)
labels= ['Female','Male']
# Plot
plt.pie(sizes,colors=colors,labels=labels,explode=explode,autopct='%1.1f%%',startangle=270,)
plt.title('Percentage of Churn by gender')
plt.show()
service= val.groupby(['PhoneService']).size().to_frame()
service
service= val.groupby(['MultipleLines']).size().to_frame()
service
service= val.groupby(['InternetService']).size().to_frame()
service
service= val.groupby(['OnlineSecurity']).size().to_frame()
service
service= val.groupby(['DeviceProtection']).size().to_frame()
service
service= val.groupby(['TechSupport']).size().to_frame()
service
service= val.groupby(['StreamingTV']).size().to_frame()
service
service= pd.pivot_table(val,index ='PhoneService',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service<jupyter_output><empty_output><jupyter_text>Let's see who Churn in all service by gender and SeniorCitizen<jupyter_code>service= pd.pivot_table(val,index ='MultipleLines',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
service= pd.pivot_table(val,index ='InternetService',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
service= pd.pivot_table(val,index ='OnlineSecurity',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
service= pd.pivot_table(val,index ='DeviceProtection',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
service= pd.pivot_table(val,index ='TechSupport',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
service= pd.pivot_table(val,index ='StreamingMovies',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
service= pd.pivot_table(val,index ='StreamingTV',columns = ['gender','SeniorCitizen'] ,aggfunc ='count',values ='customerID')
service
val1 = df_bi[df_bi.Churn=='No']
val1
y_df = df_bi['TotalCharges']
y_df
# percent of customer churn used phone service
sizes = val['PhoneService'].value_counts(sort = True)
colors = ["#BDFCC9","grey"] 
explode = (0.1,0.1)
labels= ['No','Yes'] 
# Plot
plt.pie(sizes,colors=colors,labels=labels,explode=explode,autopct='%1.1f%%',startangle=270,)
plt.title('Percentage of PhoneService ')
plt.show()
#gender who's use phone service 
ax = sns.countplot(x="PhoneService",data=val)
ax.set_title("Customer demographics PhoneService ")
service1= val.groupby(['MultipleLines','gender']).size().to_frame()
service1
#gender who's used MultipleLines and left after
# leu yo gn service tel yo moins desabonne ke leu yo genyen
ax = sns.countplot(x="MultipleLines",data=val)
ax.set_title("Customer demographics MultipleLines use it and left ")
ax = sns.countplot(x="InternetService",data=val)
ax.set_title("Customer demographics InternetService by Customer who Churn only")
ax = sns.countplot(x="OnlineSecurity",data=val)
ax.set_title("Customer demographics InternetService use by Customer who churn more ")
ax = sns.countplot(x="DeviceProtection",data=val)
ax.set_title("Customer demographics InternetService use it and left ")
ax = sns.countplot(x="TechSupport",data=val)
ax.set_title("Customer demographics InternetService use it and left ")
ax = sns.countplot(x="StreamingTV",data=val)
ax.set_title("Customer demographics InternetService use it and left ")
ax = sns.countplot(x="StreamingMovies",data=val)
ax.set_title("Customer demographics InternetService use it and left ")<jupyter_output><empty_output><jupyter_text>4 BONUS !!!<jupyter_code>round(df_bi['tenure'].mean(),2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12327896632069477, 'fraction_numerical': 0.008543387700345972, 'mean_word_length': 7.18728323699422, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '22', 'dir': 'jupyter-structured-clean-dedup', 'id': '13231', 'license': 'MIT', 'n_tokens_mistral': 4795, 'n_tokens_neox': 4519, 'n_words': 1236, 'path': 'DALCIDE_Shelsy_BI_PTROJECT.ipynb', 'repo_name': 'shelsyayiti/Churn_BI_Project', 'size': '14163'}