Lesson 3: Clustering and Segmentation
What is clustering?
Clustering groups observations by similarity in their features, without a known target label (unsupervised learning).
Use case | Features |
| Customer segmentation | Purchase frequency, average spend, category mix |
| Product grouping | Price, sales pattern, return rate |
| Store segmentation | Footfall, revenue, location type |
| Operational cases | Ticket type, resolution time, channel |
RFM (Recency, Frequency, Monetary value) is a simple, popular framework for customer segmentation and can be used with or without clustering.
Example
A retailer clusters customers using purchase frequency, average spend, and category mix:
Cluster | Frequency | Avg spend | Possible interpretation |
| 1 | High | Low | Frequent everyday shoppers |
| 2 | Low | High | Occasional big-ticket buyers |
| 3 | Low | Low | At-risk or casual customers |
| 4 | High | High | High-value loyal customers |
These labels must be interpreted from the actual results, not assumed beforehand.
How it works
k-means steps:
- Choose the number of clusters, k
- Place k starting centres
- Assign each record to its nearest centre
- Move each centre to the average of its assigned records
- Repeat steps 3–4 until assignments stabilise
Consideration | Why it matters |
| Feature scaling | Features in large units (₹) dominate those in small units (orders), so standardise first |
| Choosing k | Use the elbow method, silhouette score, and business usefulness |
| Random starts | Results can vary; run several times (scikit-learn does this by default) |
| Cluster shape | k-means assumes roughly spherical, similar-sized clusters |
| Outliers | Can pull centres away from typical customers |
Other methods: hierarchical clustering, DBSCAN (finds irregular shapes and flags noise), Gaussian mixture models.
Evaluate usefulness
Check | Question |
| Stability | Do clusters stay similar with different random starts or samples? |
| Distinctness | Are clusters meaningfully different from each other? |
| Size | Are any clusters too small to act on? |
| Interpretability | Can you describe each cluster in plain language? |
| Actionability | Would the business treat these groups differently? |
A mathematically neat segmentation isn't valuable if the groups can't be explained or acted on.
Common mistakes
- Treating clusters as natural or permanent "types" of people.
- Forgetting to scale features.
- Choosing k purely by a statistic without considering business use.
- Using too many features, which makes clusters hard to interpret.
- Never re-running: customer behaviour changes, so segments need refreshing.
Try it: Choose three numeric features for customer segmentation and explain why each one may help distinguish different usage patterns.








