ML Systems Lab Open interactive version →
Intermediate 36 min read DBSCANdensity-basedoutlier detection

DBSCAN

Core/border/noise points, eps and minPts, non-spherical clusters

You have geographic data — customer addresses mapped to (lat, lon). You want to find city clusters of any shape. K-means would fit circles; cities are not circles. DBSCAN finds density-connected regions of arbitrary shape and labels sparse areas as noise. A city center is a dense region; a rural highway stop is noise. No K to specify — the number of clusters emerges from the data's density structure.

DBSCAN parameters: ε (epsilon) — the radius defining "neighborhood." minPts — the minimum number of points in the ε-neighborhood to be a core point. Core point: has ≥ minPts points within distance ε. Border point: within ε of a core point but not itself a core point. Noise point: not within ε of any core point — explicitly labeled -1.

Density reachability: point A is directly density-reachable from core point B if A is in B's ε-neighborhood. A cluster is the connected component of core points plus their border points. The chain-following is what lets clusters take any shape — crescents, rings, L-shapes.

Parameter selection: minPts = 2 × dimensions (rule of thumb). For ε: sort all pairwise distances to the k-th nearest neighbor (k = minPts), plot the k-distance graph, pick ε at the knee where distances jump.

NOT-this: "DBSCAN does not require K, so it is always better than K-means." DBSCAN has two equally tricky hyperparameters: ε and minPts. If ε is too small, most points are noise. If too large, all points merge into one cluster. And DBSCAN does not handle clusters of varying density well — dense and sparse clusters need different ε values. HDBSCAN (hierarchical DBSCAN) handles variable density and is almost always better than vanilla DBSCAN in practice.

Key points

Takeaway

DBSCAN finds clusters of any shape and labels outliers explicitly — but a single ε threshold breaks when clusters have different internal densities, which is exactly the problem HDBSCAN was built to fix.

Recap

Check your understanding

Q1. K-means gives 5 circular clusters on GPS location data, but you suspect the true structure has non-circular geographic regions. Which two of the following are the correct setup and validation steps for DBSCAN here?

Q2. DBSCAN with eps=0.5 and minPts=5 produces 1 cluster containing 95% of data and 200 noise points. What does this indicate and what do you try?

Q3. You apply DBSCAN to customer embeddings in 128 dimensions and get mostly noise (90% of points labelled -1). What is happening and how do you fix it?

Q4. What is the difference between noise in DBSCAN and outliers detected by Isolation Forest? When would you use each for anomaly detection?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →