Clustering is an unsupervised machine learning technique that groups data points so that items in the same group are more similar to each other than to items in other groups. It does not use labels. Instead, it discovers natural groupings, such as customer segments, document topics or patterns of behaviour.
Key takeaways
- Clustering is the most common form of unsupervised learning.
- Popular algorithms include k-means, hierarchical clustering, DBSCAN and Gaussian mixture models.
- Results depend heavily on how similarity is measured and how features are scaled.
- Clusters must be interpreted and validated by people who understand the domain.
Clustering explained in simple terms
Imagine a party where guests naturally form small groups: people talking about cricket in one corner, parents discussing schools in another, developers near the snacks. Nobody assigned the groups; they formed around shared interests. Clustering finds similar natural groups in data, based on shared characteristics.
Clustering vs classification
Classification sorts items into categories you already defined, using labelled examples. Clustering discovers categories you did not define, using no labels. A common workflow uses clustering first to discover segments, then trains a classifier to assign new items to those segments quickly.
How does clustering work?
- Choose features that describe what “similar” should mean, such as spend, frequency and product mix.
- Scale features so large-number features do not dominate small-number ones.
- Pick a similarity measure, often Euclidean distance or cosine similarity.
- Run a clustering algorithm.
- Evaluate cluster quality and stability.
- Profile and name clusters, for example “high-value occasional buyers”.
Main clustering algorithms
| Algorithm | How it works | Strengths | Weaknesses |
|---|---|---|---|
| k-means | Assigns points to the nearest of k centres, then moves centres to the average of their points, repeating | Fast, simple, scales well | Must choose k; assumes round, similar-sized clusters |
| Hierarchical | Merges (or splits) groups step by step into a tree called a dendrogram | No need to fix k upfront; visual | Slow on large datasets |
| DBSCAN | Groups dense regions and marks sparse points as noise | Finds odd shapes; detects outliers | Sensitive to density settings |
| Gaussian mixture models | Treats data as a mix of overlapping bell-curve distributions | Soft membership probabilities | Assumes distribution shapes |
| HDBSCAN | A density method that handles varying densities | Robust, fewer settings | Less intuitive to explain |
How many clusters?
For k-means you must choose the number of clusters. Common aids include the elbow method, which plots how tight clusters are as k increases and looks for a bend, and the silhouette score, which measures how well each point fits its cluster compared with the nearest other cluster (ranging from -1 to 1, higher is better). In practice, the final choice should also make business sense. Seven segments nobody can act on are worse than four clear ones.
How to evaluate clusters
- Internal measures: silhouette score, Davies-Bouldin index.
- Stability: do similar clusters appear when you re-run on different samples?
- Interpretability: can each cluster be described in plain language?
- Usefulness: do actions based on clusters, such as targeted campaigns, perform better?
Limitations
Clustering always returns groups, even when the data has no real structure. Results change with feature choice, scaling and algorithm settings. High-dimensional data makes distance less meaningful, so dimensionality reduction is often applied first. Treat clusters as useful hypotheses and test them against outcomes.
