Part VI — Unsupervised Learning, Clustering, Dimensionality & Time Series · Chapter 4

Density-based clustering: DBSCAN & HDBSCAN

Hook

k-means needs to be told how many clusters to look for, and it always draws them as round, roughly equal-sized blobs. What about data that comes in two long, thin chains instead — and includes a point that doesn't belong to any group at all?

Intuition
2 cluster(s), 1 noise point(s)

Two short chains of points, plus one point sitting far off on its own. Drag eps — the neighborhood radius — and watch clusters appear, merge, and disappear. Too small, and even points one unit apart look unrelated; too large, and two genuinely separate chains fuse into one.

Formalize

DBSCAN — short for Density-Based Spatial Clustering of Applications with Noise — never asks how many clusters to expect. Instead, a point is a core point if it has enough neighbors within a radius eps:

core(i)={j:xixjeps}minPts\text{core}(i) = |\{j : \lVert x_i - x_j \rVert \leq \text{eps}\}| \geq \text{minPts}
  • core(i)\text{core}(i) — whether point ii qualifies as a core point, based on how many neighbors it has.
  • xi,xjx_i, x_j — two points in the dataset being compared.
  • eps — the neighborhood radius: how close two points must be to count as neighbors.
  • minPts — the minimum number of neighbors within eps needed for a point to be a core point.
  1. Clusters grow by hopping between core points

    A cluster is everything reachable by hopping from core point to core point, radius by radius — like a chain of falling dominoes, each one only needing to be close enough to knock over the next.

  2. Unreached points are noise

    Anything never reached this way, from any core point, is noise — not assigned to any cluster at all.

Play
0 cluster(s), 8 noise point(s)

At eps=0.5, even points exactly 11 unit apart aren't neighbors — every point is isolated, and the whole dataset is noise. At eps=1.5, both chains connect internally without merging with each other. At eps=5.0, the two chains fuse into a single cluster — genuinely different structures, collapsed together by too generous a radius.

Worked example

Two chains at y=0y=0 and y=5y=5, points spaced 11 unit apart within each chain, plus one point at (10,10)(10,10):

  1. Checking a core point

    Point (1,0)(1,0) has neighbors (0,0)(0,0) and (2,0)(2,0), both at distance exactly 11 — with eps=1.5 and minPts=1, that's enough: it's a core point.

  2. The gap between chains

    The closest pair across the two chains is (0,0)(0,0) and (0,5)(0,5), at distance exactly 55. At eps=1.5, that's nowhere close enough to connect — the chains stay two separate clusters.

  3. The point with no neighbors at all

    (10,10)(10,10)'s nearest other point is (2,5)(2,5): (102)2+(105)2=64+25=899.4\sqrt{(10-2)^2+(10-5)^2}=\sqrt{64+25}=\sqrt{89}\approx9.4 units away — far beyond any reasonable eps. It's never a core point and never reachable from one, so DBSCAN correctly leaves it as noise, folded into neither cluster.

Checkpoint

Find an eps that merges the two chains into a single cluster — without ever absorbing the far-off noise point.

2 cluster(s)
Drag eps to try it
Summary
core(i)={j:xixjeps}minPts\text{core}(i) = |\{j : \lVert x_i - x_j \rVert \leq \text{eps}\}| \geq \text{minPts}

DBSCAN trades k-means' two conveniences — pick kk up front, every point belongs to some cluster — for two things k-means can't do at all: clusters of any shape, and an explicit "doesn't belong anywhere" label for genuine outliers. Neither algorithm is strictly better; k-means assumes round, similarly-sized groups and gets a clean answer fast, while DBSCAN makes no shape assumption at all but needs eps tuned by hand, the same way kk itself did.