Skip to content

Customer Churn Analysis

Given a customer dataset with churn (0/1), analyze:

  • Overall churn rate
  • Churn by segment (plan, region)
  • Numeric differences (tenure, usage)
diagram Customer churn analysis pipeline mermaid
From raw customer records to the segments most likely to leave.
Load
import pandas as pd
 
df = pd.read_csv("data/churn.csv")
print(df.shape)
print(df.head())
Overall churn
rate = df["churn"].mean()
print("Churn rate:", rate)
Churn by segment
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
sns.barplot(data=df, x="plan", y="churn")
plt.title("Churn rate by plan")
plt.tight_layout()
plt.show()
Tenure by churn
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
sns.boxplot(data=df, x="churn", y="tenure")
plt.title("Tenure vs churn")
plt.tight_layout()
plt.show()
sketch Stayed vs churned p5.js
A donut chart makes the overall churn rate easy to read at a glance.

Step 5: Create a simple model-ready dataset

Section titled “Step 5: Create a simple model-ready dataset”
  • Handle missing values
  • Encode categories
  • Split train/test

This connects back to Phase 4 preprocessing.

Write insights:

  • Which plan/segment churns more?
  • Which features differ strongly?
  • What interventions might reduce churn?

Exercise 3 – Compare tenure between groups

Section titled “Exercise 3 – Compare tenure between groups”

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading