Start studying
Module 1 · Machine Learning Module contents
Module 1  ·  Card 37 / 55intermediate

DBSCAN

DBSCAN clusters points based on how densely packed they are.

You do not have to tell it how many clusters to look for.

It can find clusters of awkward, non-round shapes.

Points in sparse regions are labelled as noise rather than forced into a cluster.

It is sensitive to its two settings, eps and min_samples.

Learn in depth ↓
Module 01 · Machine Learning · 55 concepts
In depth  /  15 lines

DBSCAN, in more detail

DBSCAN thinks about crowding rather than distance to a centre.

A point sitting in a crowded area is called a core point.

Points near a core point join the same cluster, and clusters spread outward from there.

Points in empty regions belong to nothing and are marked as noise.

That is the big win, because outliers are not forced into a group.

You never tell it how many clusters to find, which is the other big win.

It can trace long, curved and awkward shapes that K-Means cannot.

It needs two settings instead of k, and both matter a great deal.

Eps is how close counts as near, and min samples is how many neighbours count as crowded.

Set eps too small and everything becomes noise.

Set it too large and separate clusters merge into one blob.

A common trick is to plot each point's distance to its neighbours and look for the bend.

It struggles when different clusters have very different densities.

One eps cannot describe a dense group and a sparse group at the same time.

Like anything based on distance, it needs scaled features to mean anything.

Want the full technical article? Wikipedia ↗
Deep dive

What is underneath DBSCAN

Clusters defined by density, not by distance to a centre

k-means asks which centre a point is closest to. DBSCAN asks how crowded the neighbourhood around a point is.

Nε(p)={q∈D:d(p,q)≤ε}N_\varepsilon(\mathbf{p}) = \{ \mathbf{q} \in D : d(\mathbf{p}, \mathbf{q}) \leq \varepsilon \}
  • ε\varepsilon: the radius that defines a neighbourhood.
  • DD: the whole dataset.
  • minPts\mathrm{minPts}: how many points that neighbourhood must contain.
p is a core point  ⟺  ∣Nε(p)∣≥minPts\mathbf{p} \text{ is a core point} \iff |N_\varepsilon(\mathbf{p})| \geq \mathrm{minPts}

A core point sits in a crowd. A border point is inside some core point's neighbourhood without being crowded itself. Everything else is noise.

One run, in order

  1. Pick an unvisited point and find every point within ε\varepsilon of it.
  2. If there are fewer than minPts\mathrm{minPts}, mark it noise for now and move on.
  3. If there are enough, open a new cluster and add all of them to it.
  4. For each new member that is itself a core point, add its neighbourhood to the cluster too.
  5. Stop expanding when no member adds anyone new, then start again from another unvisited point.

A point marked noise in step two can still be claimed later as a border point, because being inside somebody else's crowd is enough.

What this buys over k-means

The number of clusters is an output rather than an input, which is the difference people notice first.

Clusters take any shape at all, because membership spreads point to point instead of radiating from a centre.

Noise is a first-class answer, so outliers are labelled as outliers rather than forced into the nearest cluster.

The two parameters, and how to set them

minPts≥d+1\mathrm{minPts} \geq d + 1

A common starting rule is twice the number of dimensions, with a floor at d+1d + 1, and higher on noisy data.

For ε\varepsilon, compute each point's distance to its kk-th nearest neighbour where k=minPtsk = \mathrm{minPts}, sort those distances and plot them.

The curve stays flat and then bends sharply upward. That bend is where points stop being in a crowd, and its height is a good ε\varepsilon.

Where it fails

O(nlog⁡n)O(n \log n)

With a spatial index the run costs that much, and it degrades to O(n2)O(n^2) in high dimensions where the index stops helping.

One ε\varepsilon is applied everywhere, so data with a dense cluster and a sparse one cannot be handled by any single value.

That case is what OPTICS and HDBSCAN exist for, and it is the standard reason to reach past DBSCAN.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What does DBSCAN do with a point sitting in a sparse region?
Machine Learning

55 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close