cosine

Untitled Notebook

Ready for analysis
In [1]

Analyzing Customer Churn

This notebook analyzes a dataset of customer churn to identify key factors and build a predictive model.

NOTE: This is a demo, the kernel and integrations are not live.

In [2]
1import pandas as pd
2import numpy as np
3import matplotlib.pyplot as plt
4import seaborn as sns
In [3]
1# Let's create a dummy dataset
2data = {
3    'customerID': ['1869-IIUWF', '4472-LVYGI', '2410-SHYSP', '9892-BOWSO', '3333-QDXSI'],
4    'gender': ['Female', 'Male', 'Female', 'Male', 'Male'],
5    'tenure': [3, 29, 2, 7, 1],
6    'PhoneService': ['Yes', 'Yes', 'No', 'Yes', 'Yes'],
7    'Contract': ['Month-to-month', 'One year', 'Month-to-month', 'Month-to-month', 'Month-to-month'],
8    'PaymentMethod': ['Electronic check', 'Bank transfer (automatic)', 'Mailed check', 'Mailed check', 'Electronic check'],
9    'MonthlyCharges': [70.35, 95.0, 20.25, 45.4, 39.2],
10    'TotalCharges': [200.9, 2826.0, 41.5, 316.9, 39.2],
11    'Churn': ['Yes', 'No', 'No', 'Yes', 'No']
12}
13df = pd.DataFrame(data)
14print(df.head())
In [4]
1# Check for missing values
2print(df.isnull().sum())
In [5]

Data Exploration & Visualization

In [6]
1sns.set_theme(style='whitegrid')
In [7]
1# Analyze churn by contract type
2plt.figure(figsize=(8, 5))
3sns.countplot(x='Contract', hue='Churn', data=df)
4plt.title('Churn by Contract Type')
5plt.show()
In [8]
1# Analyze churn by gender
2plt.figure(figsize=(8, 5))
3sns.countplot(x='gender', hue='Churn', data=df)
4plt.title('Churn by Gender')
5plt.show()
In [9]
1SELECT PaymentMethod, COUNT(*) as ChurnCount
2FROM df
3WHERE Churn = 'Yes'
4GROUP BY PaymentMethod
5ORDER BY ChurnCount DESC
In [10]

Conclusion

Based on the analysis, customers on a month-to-month contract are more likely to churn. The payment method also seems to influence churn, with electronic checks having the highest churn count in our SQL query.