Choosing a clustering method
There's more than one way to group similar observations. The right method depends on the shape and density of your data, how many clusters you expect, and what you want the clusters for.
Want to segment customers by how they shop, find survey respondents who answer alike, or flag unusual movement in sensor data? That's a job for cluster analysis. Just keep in mind that not every dataset actually breaks into clean groups.
Clustering is unsupervised learning: there are no labels telling you the right answer, so the method has to find and group similar cases on its own. Run it on the same data with a different distance measure, or a different assumption about cluster shape, and you can get different groups.
This guide covers when to reach for each of seven common methods. For the details of how each one works and how to read its output, see that method's own page.
Four questions to answer before you pick a method
Look at the structure of your data and your goal before the algorithm.
A map for choosing a clustering method
Narrow the field by cluster shape and by what you need from the result.
If you expect your customers to fall into a few fairly distinct groups, K-Means is a reasonable place to start. If the cluster boundaries wind around, or there are oddball observations mixed in, a density-based method may fit better.
Treat the map as a starting point, though. Rather than settling on one algorithm right away, run several candidates on the same data and compare.
When you set the number of clusters up front
These methods build clusters around a representative point.
When you need something fast and simple
K-Means splits the data so that observations sit as close as possible to their cluster's center. You have to choose the number of clusters yourself, and it's a good first pass on large tabular datasets. It can struggle, though, with outliers and with long, curving clusters.
When you want a real observation as the center
K-Medoids picks an actual data point to represent each cluster. It's generally less sensitive to outliers than K-Means, but it can take a lot more computing.
Say you want to sort customers into 3 to 5 groups based on things like how much they spend and how often they visit. K-Means is a fine place to start. If a few big spenders are dragging the centers around, try K-Medoids as well and compare.
When clusters are irregular or the data are noisy
Density-based methods separate crowded regions from scattered points.
When you want to find groups by how crowded the neighborhood is
DBSCAN links up regions where points are packed closely enough into clusters, and it can label points that don't fit anywhere as noise. It handles curved clusters well, but when density varies a lot across the data, no single distance cutoff works everywhere.
When clusters differ in density
HDBSCAN looks across many density levels and keeps the clusters that stay stable. You don't have to fix the number of clusters in advance, but you should still check how to interpret small groups and how much the settings change the result.
When your map has dense areas, like downtown, alongside sparse ones, like the suburbs, compare what DBSCAN and HDBSCAN give you. With either method, it's fine to leave some points out of every cluster.
When you want membership probabilities or a hierarchy
How you plan to use the result calls for a different approach.
When a case could belong to more than one cluster
A Gaussian mixture model (GMM) gives each observation a probability of belonging to each cluster. That's handy when the boundaries between clusters are fuzzy, but you need to check the assumption that the components are Gaussian and think carefully about how many components to use.
When you want to see the order clusters form in
Hierarchical cluster analysis (HCA) merges similar cases step by step (or splits them apart) and draws the whole process as a dendrogram. The shape of that tree can change a lot depending on the distance measure and linkage method you choose.
When you want to lay out high-dimensional data like a map
A self-organizing map (SOM) places high-dimensional observations on a 2-D grid so that similar patterns end up near each other. It's great for exploring and visualizing structure, but two cases sitting close together on the map doesn't by itself mean you've found a real cluster.
What to check before you run it
Clustering results swing a lot with preprocessing and validation choices.
| Check | Why it matters |
|---|---|
| Variable selection | Lots of variables unrelated to your goal will blur what the clusters mean. |
| Scaling and distance | A variable measured in bigger units can dominate the distance calculation. Decide on standardization and the distance measure together. |
| Missing values and outliers | How you handle missing and extreme values shifts the cluster centers and the density estimates. |
| Number of clusters and settings | Vary the number of clusters, the neighborhood radius, the minimum cluster size, and so on, and see whether the results hold steady. |
| Validating the result | Don't stop at the silhouette score. Also look at stability under resampling, the group sizes, and whether the clusters line up with outside information. |
All 7 clustering methods at a glance
Each method's own page covers how it works and how to read its results.
Understand the shape of your clusters and your goal, and the method choice gets easy.
K-Means and K-Medoids work from representative centers, DBSCAN and HDBSCAN from density, GMM from membership probabilities, HCA from a hierarchy, and SOM from a map of high-dimensional patterns.
First decide what you need: representative centers, dense regions separated from noise, or membership probabilities and a hierarchy. Then compare the candidate methods while checking variable scales, outliers, and how stable the clusters stay as you change the preprocessing and settings.
What matters isn't how many groups you end up with, but whether the split shows up again and again and actually helps answer your question. And any names you give the clusters should come from the features of the observations, not from the algorithm.