DBSCAN
DBSCAN — Cluster by density; label sparse points as noise.
DBSCAN finds clusters as dense regions separated by sparse gaps. Unlike k-means, it discovers the number of clusters itself, handles weird shapes, and calls isolated points noise.
- Cluster 1
- Cluster 2
- Noise
- On the frontier
- Being probed (ε-ball)
DBSCAN controls
The idea in plain words
DBSCAN finds clusters as dense regions separated by sparse gaps. A point is a “core” point if enough neighbors sit within a radius ε; clusters grow by connecting core points and their neighbors, and anything left isolated is labeled noise.
Unlike k-means, it discovers the number of clusters itself and handles arbitrary shapes — on two moons it cleanly separates the crescents that k-means fundamentally cannot.
Now, the math
A point p is a core point when its ε-neighborhood is dense enough:
- the neighborhood radius — the density scale.
- how many neighbors within ε make a point a core point.
- the set of points within ε of p.
▸ Show the derivation
Clusters are maximal sets of density-connected points: start at any core point and absorb every point reachable through a chain of core-point neighborhoods. ε sets the density threshold — too small and every point is isolated noise; too large and separate clusters merge into one blob.
Trace it by hand
Five points — A(1,1), B(2,1), C(1,2), D(3,1), E(6,5) — with epsilon = 1.5 and minPts = 3. A point counts itself in its own neighborhood. We classify B, D, and E (distances rounded to 2 places).
Step 1 — B has a crowded neighborhood: core point
A and C are core too, each with a neighborhood of exactly 3. The cluster grows outward from these core points.
Step 2 — D is reachable but not dense: border point
D's next-nearest point after B is A at distance 2, outside epsilon. Border points join a cluster without extending it.
Step 3 — E is isolated: noise
No core point can reach E, so it never receives a cluster id.
Step 4 — the final labeling
Nobody told DBSCAN to find one cluster — the density threshold discovered it, and flagged the outlier for free.
What just happened: Counting neighbors within epsilon = 1.5 sorted the points into three roles: dense cores (A, B, C), an attached border (D), and unreachable noise (E) — cluster count and outliers both fell out of the density rule.
Now Break It
Try this: Wrong epsilon either merges everything into one blob or marks almost every point as noise.
Control: Epsilon slider (set very small or very large)
What happens: Wrong density scale! Epsilon too small marks everything as noise; too large merges all clusters.
Where dbscan is used
DBSCAN clusters points by density, which lets it find groups of arbitrary shape and flag outliers as noise in the same pass. This makes it a natural fit for spatial data such as identifying dense regions of GPS coordinates, detecting hotspots of crime or disease reports, and grouping stars or galaxies in astronomy. Anomaly detection is a headline use: because DBSCAN explicitly labels sparse points that belong to no dense region as noise, it can surface fraudulent transactions or faulty sensor readings without a separate outlier model. Unlike centroid methods, it does not require you to specify the number of clusters ahead of time, and it happily separates a ring-shaped cluster from a blob nested inside it, which partitioning algorithms cannot do.
The most common pitfall is expecting good results without tuning the two parameters: eps, the neighborhood radius, and minPts, the minimum points needed to form a dense region. Set eps too small and everything becomes noise; too large and distinct clusters merge into one. A deeper limitation is that a single global eps assumes roughly uniform density, so DBSCAN struggles when some clusters are dense and others sparse, which is what motivated the HDBSCAN extension. People also forget that distance-based density is sensitive to feature scaling and degrades in high dimensions, where distances concentrate. Finally, DBSCAN is not fully deterministic: border points reachable from multiple clusters can be assigned differently depending on processing order.
Frequently asked questions
What do the eps and minPts parameters mean?
How do I pick a good value for eps?
Why does DBSCAN label some points as noise?
When should I use DBSCAN instead of K-Means?
Why does DBSCAN perform poorly on my high-dimensional data?
Written & reviewed by the ML Visualization team · Last updated .