Search⌘ K
AI Features

Segmentation Analysis and Applying Domain Knowledge

Explore how to use segmentation analysis to uncover hidden patterns in customer churn data by breaking metrics into meaningful groups. Learn to interpret churn rates alongside segment sizes, apply domain knowledge for investigation, and turn findings into actionable checks before modeling.

A subscription churn table can report an overall churn rate of 12% and still hide the decision that matters. If churn is 25% for customers on Basic plans in one region but 8% elsewhere, a single average does not tell us where to investigate. Segmentation analysis slices a metric into meaningful groups, such as region, plan_tier, or signup_month, to expose patterns an aggregate hides.

The complete workflow below creates a small subscription table, checks its overall churn rate and segment sizes, computes segmented rates, and prepares the descriptive evidence we need before proposing any follow-up. It expects one row per customer and a churned column coded as 0 or 1.

Python
import pandas as pd
def main() -> None:
# One row per customer; churned is coded as 0/1 so mean(churned) is the churn rate.
subscriptions = pd.DataFrame(
{
"user_id": range(1, 33),
"signup_month": [
"2024-01",
"2024-01",
"2024-01",
"2024-01",
"2024-01",
"2024-01",
"2024-02",
"2024-02",
"2024-02",
"2024-02",
"2024-02",
"2024-02",
"2024-02",
"2024-02",
"2024-03",
"2024-03",
"2024-03",
"2024-03",
"2024-03",
"2024-03",
"2024-03",
"2024-04",
"2024-04",
"2024-04",
"2024-04",
"2024-04",
"2024-04",
"2024-04",
"2024-05",
"2024-05",
"2024-05",
"2024-05",
],
"region": [
"North",
"North",
"North",
"South",
"South",
"West",
"North",
"North",
"South",
"South",
"West",
"West",
"West",
"East",
"North",
"South",
"South",
"West",
"West",
"East",
"East",
"North",
"North",
"South",
"South",
"West",
"West",
"East",
"North",
"South",
"West",
"East",
],
"plan_tier": [
"Basic",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Pro",
"Pro",
"Basic",
"Basic",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Pro",
"Basic",
"Basic",
"Pro",
"Pro",
"Basic",
],
"churned": [
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
}
)
overall_churn_rate = subscriptions["churned"].mean()
print("Subscriptions summary")
print(f"rows: {subscriptions.shape[0]}")
print(f"overall_churn_rate: {overall_churn_rate:.2%}")
print()
region_counts = subscriptions["region"].value_counts(dropna=False)
plan_counts = subscriptions["plan_tier"].value_counts(dropna=False)
print("Row counts by region")
print(region_counts.to_string())
print()
print("Row counts by plan_tier")
print(plan_counts.to_string())
if __name__ == "__main__":
main()
  • Lines 6–146: The code constructs an in-memory, one-row-per-customer subscription table with region, plan_tier, signup_month, and a binary churned column so later summaries treat the table at customer grain.

  • Line 148: The code uses mean() on the 0/1 churned values to produce the overall churn rate as a proportion.

  • Lines 155–156: value_counts(dropna=False) reports how many rows fall into each segment label (including any missing labels, if present), which is the context needed to interpret whether an aggregate rate could be dominated by one group.

  • Lines 150–153 and 158–163: The code prints the baseline overall churn rate alongside the region and plan-tier row-count ...