Customer Churn Analysis
Given a customer dataset with churn (0/1), analyze:
- Overall churn rate
- Churn by segment (plan, region)
- Numeric differences (tenure, usage)
Analysis pipeline
Section titled “Analysis pipeline”flowchart LR A["Raw customers
(churn 0/1)"] --> B["Rate
(overall churn %)"] B --> C["Segment
(by plan, region)"] C --> D["Visualize
(churn by segment)"] D --> E["Model-ready
(encode, split)"]
Step 1: Load
Section titled “Step 1: Load”import pandas as pd
df = pd.read_csv("data/churn.csv")
print(df.shape)
print(df.head())Step 2: Churn rate
Section titled “Step 2: Churn rate”rate = df["churn"].mean()
print("Churn rate:", rate)Step 3: Churn by category
Section titled “Step 3: Churn by category”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()Step 4: Numeric differences
Section titled “Step 4: Numeric differences”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()Visualize it
Section titled “Visualize it”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.
Deliverable
Section titled “Deliverable”Write insights:
- Which plan/segment churns more?
- Which features differ strongly?
- What interventions might reduce churn?
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Overall churn rate
Section titled “Exercise 1 – Overall churn rate”Exercise 2 – Churn rate by plan
Section titled “Exercise 2 – Churn rate by plan”Exercise 3 – Compare tenure between groups
Section titled “Exercise 3 – Compare tenure between groups”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading