← Choosing an analysis
Choosing an analysis

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.

Distance-basedDensity-basedModel-basedHierarchies & maps7 methods

Noise?Grouping similar points, no answer key

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.

SECTION 01

Four questions to answer before you pick a method

Look at the structure of your data and your goal before the algorithm.

01 / GOALWhy are you clustering?To sum up similar cases in a handful of groups, or to pick out the odd cases?
02 / SHAPEWhat shape are the clusters?Tight, round blobs, or winding shapes and groups of different density?
03 / SIZEDo you know how many clusters you want?Is there a target number of groups, or does the data need to tell you?
04 / DATADo the distances make sense?Check variable scales, outliers, sample size, and whether the data are high-dimensional.
Round blobsK-MeansCurved shapesDBSCANUneven density, noiseHDBSCANOverlapping groupsGMM
Figure 1. Which method fits which cluster shape (conceptual)
Keep this in mind: unlike classification, clustering has no answer key of known labels. A neat-looking split doesn't, on its own, prove the groups mean anything.
SECTION 02

A map for choosing a clustering method

Narrow the field by cluster shape and by what you need from the result.

How should we group the data?Group by distanceCenters · you set kK-MeansK-MedoidsComplex shapes, noiseDensity · finds k itselfDBSCANHDBSCANOther structuresProbability · hierarchy · mapGMM (membership prob.)HCA (dendrogram)SOM (2-D map)Compare several candidates on the same data · check scaling and stability
Figure 2. Decision map for choosing a clustering method

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.

SECTION 03

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.

K-Means: the mean is the centerOutlierCenter gets pulledtoward the outlierK-Medoids: a real point is the centerOutlier
Figure 3. K-Means vs. K-Medoids (conceptual)
Example · Customer shopping patterns

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.

SECTION 04

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.

DBSCAN: curved shapes + noise ✕HDBSCAN: clusters of different densityCluster 1Cluster 2Noise (no cluster)
Figure 4. Density-based clustering (conceptual)
Example · Location data

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.

SECTION 05

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.

GMMThe circled pointCluster 150%Cluster 250%
Figure 5. GMM membership probabilities (conceptual)

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.

HCA: dendrogramABCDEFGHCut here:4 clustersSOM: 2-D grid mapSimilar patterns land in nearby cells
Figure 6. A dendrogram and a SOM grid (conceptual)
SECTION 06

What to check before you run it

Clustering results swing a lot with preprocessing and validation choices.

CheckWhy it matters
Variable selectionLots of variables unrelated to your goal will blur what the clusters mean.
Scaling and distanceA variable measured in bigger units can dominate the distance calculation. Decide on standardization and the distance measure together.
Missing values and outliersHow you handle missing and extreme values shifts the cluster centers and the density estimates.
Number of clusters and settingsVary the number of clusters, the neighborhood radius, the minimum cluster size, and so on, and see whether the results hold steady.
Validating the resultDon't stop at the silhouette score. Also look at stability under resampling, the group sizes, and whether the clusters line up with outside information.
Unscaled: income ($) dominatesIncome →Visits ↑Standardized: both count equallyIncome →Visits ↑
Figure 7. How variable scale affects distance (conceptual)
A word of caution: finding a cluster doesn't hand you its cause, its character, or its name. Compare each cluster's profile against the raw data before you interpret it.
SECTION 07

All 7 clustering methods at a glance

Each method's own page covers how it works and how to read its results.

✓ KEY TAKEAWAYS

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.