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
- 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.
- Explored relationships, and dropped recency and tenure, which correlated with almost nothing.
- Scaled 15 numeric features so no unit, like dollars, dominates the distances.
- 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, 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.