Menu

Clustering and Segmentation

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 segmentationPurchase frequency, average spend, category mix
Product groupingPrice, sales pattern, return rate
Store segmentationFootfall, revenue, location type
Operational casesTicket 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

1HighLowFrequent everyday shoppers
2LowHighOccasional big-ticket buyers
3LowLowAt-risk or casual customers
4HighHighHigh-value loyal customers

These labels must be interpreted from the actual results, not assumed beforehand.

How it works

k-means steps:

  1. Choose the number of clusters, k
  2. Place k starting centres
  3. Assign each record to its nearest centre
  4. Move each centre to the average of its assigned records
  5. Repeat steps 3–4 until assignments stabilise

Consideration

Why it matters

Feature scalingFeatures in large units (₹) dominate those in small units (orders), so standardise first
Choosing kUse the elbow method, silhouette score, and business usefulness
Random startsResults can vary; run several times (scikit-learn does this by default)
Cluster shapek-means assumes roughly spherical, similar-sized clusters
OutliersCan pull centres away from typical customers

Other methods: hierarchical clustering, DBSCAN (finds irregular shapes and flags noise), Gaussian mixture models.

Evaluate usefulness

Check

Question

StabilityDo clusters stay similar with different random starts or samples?
DistinctnessAre clusters meaningfully different from each other?
SizeAre any clusters too small to act on?
InterpretabilityCan you describe each cluster in plain language?
ActionabilityWould 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.


Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details