Foundations to Frontier
Tests

DBSCAN

DBSCAN (Density-Based Spatial Clustering of Applications with Noise; Ester, Kriegel, Sander and Xu, 1996) defines clusters as dense regions separated by sparse ones. A point with at least minPts neighbours within radius ε is a core point. Core points within ε of each other belong to the same cluster, border points lie within ε of a core point, and everything else is noise. It finds clusters of any shape, needs no k, and labels outliers explicitly, but it needs a sensible ε and fails when clusters have very different densities. This page covers core, border and noise points, density-reachability, the algorithm and its cost with spatial indexes, choosing ε with the k-distance plot, and the single-density limitation. In the exercises you implement DBSCAN and verify it against connected components; then you map how results depend on ε for moons and for clusters of different density.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Clusters are crowds; loners are noise

Draw a circle of radius ε around each point. If the circle holds at least minPts points, that point is in a crowd (a core point). Crowds that touch merge into one cluster. Points near a crowd but not crowded themselves join it as border points. Everyone else is noise. There is no k to choose, any shape is allowed, and outliers are flagged automatically.

DBSCAN: clusters are dense regions
××××××××××××××××××××××sorted 4-NN distanceε
clusters 2 · noise points 22 of 350 · core points 322
Big dots are core points, small dots border points, × noise. On the moons, a fairly wide range of ε finds both moons and leaves the scattered points as noise. The k-distance curve bends upward where noise points begin, a common guide for picking ε. With different densities no single ε works: small ε separates the two tight blobs but shreds the sparse one into noise, and large ε keeps the sparse one but merges the tight pair.
Why engineers care

Real data has odd shapes and junk: radar returns, GPS tracks, lidar points, anomalous telemetry. DBSCAN finds arbitrarily shaped groups and reports outliers as noise rather than forcing them into a cluster. That is ideal for spatial data such as lidar object segmentation, hotspot detection or aircraft holding patterns.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A core point has…
  2. 2. DBSCAN needs you to choose…
  3. 3. Points in no dense region are…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Point types by hand

Data 0, 0.5, 1, 1.5, 5 on a line, ε = 0.6, minPts = 3 (each count includes the point itself).

point neighbours within 0.6 count type
0 0, 0.5 2 border (0.5 is core)
0.5 0, 0.5, 1 3 core
1 0.5, 1, 1.5 3 core
1.5 1, 1.5 2 border (1 is core)
5 5 1 noise

The two core points are within ε of each other, so there is 1 cluster of 4 points and 1 noise point.

k-distance. For points 0, 1, 3, each point’s distance to its nearest other point is 1, 1, 2. The sorted curve rises sharply where sparse points begin. Choose ε near that bend.

The steps in plain English:

  1. For each point, find its ε-neighbourhood (with a k-d tree or ball tree).
  2. Mark core points: at least minPts neighbours.
  3. Take an unlabelled core point and start a new cluster. Add its neighbours, and keep expanding through any neighbour that is itself core (breadth-first search).
  4. Repeat until every core point is labelled. Non-core points reached are border points; the rest are noise.
📝 Quick check (Level 1)
0/3 answered
  1. 1. In the example, what type is the point 1.5?
  2. 2. How many clusters in the example?
  3. 3. Does a border point extend the cluster further?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Reachability, cost, and choosing ε

Definitions (Ester et al., 1996).

  • q is directly density-reachable from p if p is core and q is within ε of p.
  • Density-reachable means reachable through a chain of such steps.
  • p and q are density-connected if both are density-reachable from some core point.

A cluster is a maximal set of density-connected points. For core points, clusters are exactly the connected components of the graph that links core points within ε (verified in exercise 1). Border points within ε of cores from two clusters are assigned to whichever cluster reaches them first. That is the only order-dependence.

Cost. With a spatial index, each range query costs about O(log n) in low dimension, so DBSCAN is about O(n log n) on average. It is O(n²) in the worst case, or with no index in high dimensions.

Choosing the parameters.

  • minPts: a rule of thumb is about 2 × dimension (Sander et al., 1998), and at least 3–4. Larger values smooth out noise.
  • ε: plot the sorted distance to the (minPts − 1)-th neighbour and pick the knee.
  • On moons with scattered noise (exercise 2), every ε from 0.15 to 0.25 gave a perfect ARI, and the knee heuristic picked 0.129 (ARI 0.93), just below that range.

The single-density limitation. One ε means one density threshold. If one cluster is far sparser than others, a small ε shreds it into noise, and a large ε merges nearby dense clusters. Exercise 2: on two tight blobs 0.6 apart plus one sparse blob, the best single ε reached only ARI 0.745. HDBSCAN and OPTICS (next topics) remove this limit.

from sklearn.cluster import DBSCAN
from sklearn.neighbors import NearestNeighbors
kd = np.sort(NearestNeighbors(n_neighbors=5).fit(X).kneighbors(X)[0][:, -1])    # look for the knee
labels = DBSCAN(eps=0.15, min_samples=5).fit_predict(X)                          # −1 = noise
🐍 Exercise 1: DBSCAN
Implement ε-neighbourhoods, core points and the breadth-first cluster expansion; check that core-point clusters are the connected components of the core ε-graph and that noise points have no core neighbour.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For core points, DBSCAN clusters are…
  2. 2. DBSCAN's result can depend on processing order only for…
  3. 3. Typical cost with a spatial index in low dimension?

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Determinism. Core points and noise points are uniquely determined by (ε, minPts). Only border points shared by two clusters can change with order. DBSCAN* (Campello et al., 2013) treats border points as noise, which makes the result fully deterministic.

Relation to single linkage. With minPts = 2 every point with any neighbour is core, and DBSCAN’s clusters equal the single-linkage clusters cut at height ε (minus singletons, which become noise). Larger minPts makes it a robust single linkage that ignores thin chains. That is how DBSCAN resists the chaining that defeated single linkage on bridged blobs.

Level-set view. DBSCAN approximates the connected components of a density level set, the regions where an estimated density exceeds a threshold set by minPts and ε. One threshold cannot capture clusters that live at different density levels. HDBSCAN builds the whole hierarchy of level sets instead.

High dimensions. Distances concentrate, so ε-neighbourhoods are either nearly empty or nearly everything. Reduce dimension first, or use a distance suited to the data.

Interview questions.

  • When does DBSCAN fail? With clusters of very different density, in high dimensions, and when there is no clear density gap between clusters.
  • How do you pick ε? From the k-distance knee with k = minPts − 1, from domain scale (for example a physical distance in metres), and by checking the stability of the cluster count over nearby ε.
📝 Quick check (Level 3)
0/3 answered
  1. 1. With minPts = 2, DBSCAN clusters match…
  2. 2. DBSCAN* makes results deterministic by treating border points as…
  3. 3. DBSCAN approximates connected components of a…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

How forgiving is ε?

History.

  • M. Ester, H.-P. Kriegel, J. Sander and X. Xu (KDD 1996) introduced DBSCAN. It won the KDD test-of-time award in 2014.
  • J. Sander et al. (1998) generalised it as GDBSCAN.
  • E. Schubert et al. (2017) re-examined its use and the choice of parameters in “DBSCAN revisited, revisited”.
  • R. Campello, D. Moulavi and J. Sander (2013) introduced DBSCAN* and HDBSCAN.

Exercise 2. minPts = 5, ε on a grid from 0.05 to 0.6, 3 datasets each. ARI is computed on the real points, with any real point called noise counted as its own singleton.

data best ε best ARI ε range within 0.05 of best k-distance knee ε ARI at knee
two moons + 40 noise points 0.175 1.000 0.100 wide 0.129 0.932
two tight blobs + one sparse blob 0.150 0.745 0.075 wide 0.227 0.453
  • On the moons DBSCAN was perfect over a usable band (ε 0.15–0.25), and the knee heuristic landed just below it, still at ARI 0.93.
  • With mixed densities no ε was good. The best kept the tight blobs apart but lost much of the sparse blob to noise (0.745). The knee chose an ε that merged the tight pair (0.453).
  • The knee follows the bulk density, so it fails exactly when densities differ: the motivation for HDBSCAN.
🐍 Exercise 2 (research): sensitivity to ε
For moons with noise and for blobs of different density, sweep ε for DBSCAN (minPts = 5), record the best ARI and how wide the good range is, and evaluate the k-distance knee heuristic.

DBSCAN in AI, robotics and aerospace

  • Lidar and radar point-cloud segmentation: grouping returns into objects and discarding clutter as noise.
  • Trajectory hotspots: finding holding patterns, congestion or loitering from ADS-B positions.
  • Anomaly screening: telemetry points labelled noise by DBSCAN are candidates for investigation.

References

  1. M. Ester, H.-P. Kriegel, J. Sander, X. Xu (1996). “A density-based algorithm for discovering clusters in large spatial databases with noise.” Proc. KDD.
  2. E. Schubert, J. Sander, M. Ester, H.-P. Kriegel, X. Xu (2017). “DBSCAN revisited, revisited: why and how you should (still) use DBSCAN.” ACM Transactions on Database Systems 42(3).
  3. J. Sander, M. Ester, H.-P. Kriegel, X. Xu (1998). “Density-based clustering in spatial databases: the algorithm GDBSCAN and its applications.” Data Mining and Knowledge Discovery 2.
  4. R. J. G. B. Campello, D. Moulavi, J. Sander (2013). “Density-based clustering based on hierarchical density estimates.” Proc. PAKDD.
  5. scikit-learn developers. “DBSCAN.” Documentation.