Case study · AI & Data Science Program · Project 1

Customer Segmentation with K-means

Who are a retailer's customers, really? Two clear segments emerged: higher-income households that spend across every channel, and younger families who browse the web more, spend less and buy on deals.

  • 922 / 1,318customers in segments A and B
  • 2,240customers, 29 attributes
  • k = 2chosen by silhouette score
  • 92.4%of variance needed 11 of 15 PCA components

2,240 customers

A · 922B · 1,318
  • Segment A (922): established, high-spending
  • Segment B (1,318): younger families
PCA needed 11 of 15 components for 92.4% of variance, so I clustered on scaled features. k = 2, the best silhouette score.

Scaled features, not PCA components.

Marketers need segments in real features, and keeping 92.4% of the variance needed 11 of 15 components.
On this page

Problem

A growing retailer marketed to everyone the same way and wanted to know which customer groups exist and how to reach each. With no “right answer” column, the hard part is judgment: which features, how many groups, and whether they mean anything to a marketer.

Data: 2,240 customers, 29 attributes: demographics, two years of spending in six categories, purchases by channel, web visits and campaign responses. Program certificate (external site).

Result / Impact

Two segments, in mean scaled values (0 = the average customer):

Measure Segment A: established, high-spending (922) Segment B: younger families (1,318)
Income +0.77 −0.54
Spending, all six categories +0.60 to +0.86 −0.42 to −0.60
Catalog and store purchases +0.88 and +0.84 −0.62 and −0.59
Web visits per month −0.68 +0.47
Deal purchases −0.18 +0.12
Children at home −0.71 +0.49
Age +0.17 −0.12

What I’d tell marketing:

  • Segment A spends across every channel and rarely buys on deals. Don’t train them to wait for discounts; invest in retention, premium ranges (wine and meat) and catalog and in-store experiences.
  • Segment B visits the website often but spends less and likes deals. Target them online with family offers and web-only deals, and measure whether visits become larger baskets.

What I did

Cleaning, scaling, PCA tested and rejected
  1. Cleaned the data: missing income (24 records) set to the median ($51,381.50), since outliers pull the mean; three impossible ages (126, 127, 133) set to the valid mean (57); odd marital statuses (“Alone”, “Absurd”, “YOLO”) mapped.
  2. Explored relationships, and dropped recency and tenure, which correlated with almost nothing.
  3. Scaled 15 numeric features so no unit, like dollars, dominates the distances.
  4. Tested PCA and rejected it, then chose k with the elbow plot and silhouette score, fit K-means and profiled the clusters.

Tools: Python, Pandas, NumPy, scikit-learn (StandardScaler, PCA, KMeans, silhouette score), Matplotlib, Seaborn, Google Colab.

Decisions

Scaled features, and two segments rather than three

Scaled features, not PCA components. Context: marketers need segments in real features. Options: K-means on principal components; on 15 scaled features. Decision: scaled features; keeping 92.4% of the variance needed 11 of 15 components. Consequences: directly explainable clusters.

Two segments, not three. Context: the elbow plot was ambiguous between 2 and 3. Options: k = 2; k = 3. Decision: k = 2, the best silhouette score. Consequences: two campaigns a team can actually run.

What I’d do next

  • Test k = 3 and Gaussian mixtures; validate segments against past campaign responses before spending on them.
  • Compute tenure from a fixed reference date too (age already uses one), for reproducible results.

Design, not experience

How I’d run this in production on Databricks (design, not production experience)

Nightly Delta ingestion with expectations that quarantine impossible ages; a customer feature table; scaling and K-means as one MLflow-logged pipeline; weekly segments written to a Gold table; alerts when segment sizes or profiles drift.

Next case study

  • AI & Data Science Program · Project 2

    85%of converting leads found

    Lead-conversion prediction

    Decision tree and random forest on 4,612 leads, tuned for recall.

Need a Claude agent or data workflow built? Work with me