close
Skip to content
ML Visualization

DBSCAN

Unsupervised & Dim. ReductionIntermediate~7 min

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.

Every point, in index order — frontier 0 queued
  • Cluster 1
  • Cluster 2
  • Noise
  • On the frontier
  • Being probed (ε-ball)

DBSCAN controls

Data
Dataset
30
1.0×

Drag any point, or click empty space to drop a new one — the search re-runs from scratch.

Model
1.10
4
Clusters2
Noise2 / 60
Playback
Step 0 / 337
Speed
  1. Probe
  2. Seed a cluster
  3. Expand
  4. Or mark noise
  5. Done

Step 0 of 337 — probing point 0 — its ε-ball holds 5 points, and minPts is 4

Break it

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:

Nε(p)minPts|N_\varepsilon(p)| \geq \text{minPts}
ε\varepsilon
the neighborhood radius — the density scale.
minPts\text{minPts}
how many neighbors within ε make a point a core point.
Nε(p)N_\varepsilon(p)
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).

  1. Step 1 — B has a crowded neighborhood: core point

    d(B,A)=1,    d(B,C)=1.41,    d(B,D)=1    ε    Nε(B)=43d(B,A) = 1,\;\; d(B,C) = 1.41,\;\; d(B,D) = 1 \;\le\; \varepsilon \;\Rightarrow\; |N_\varepsilon(B)| = 4 \ge 3

    A and C are core too, each with a neighborhood of exactly 3. The cluster grows outward from these core points.

  2. Step 2 — D is reachable but not dense: border point

    Nε(D)={D,B},Nε(D)=2<3,DNε(B)N_\varepsilon(D) = \{D, B\},\quad |N_\varepsilon(D)| = 2 < 3, \qquad D \in N_\varepsilon(B)

    D's next-nearest point after B is A at distance 2, outside epsilon. Border points join a cluster without extending it.

  3. Step 3 — E is isolated: noise

    minjd(E,j)=d(E,D)=5>ε    Nε(E)=1\min_j d(E, j) = d(E,D) = 5 > \varepsilon \;\Rightarrow\; |N_\varepsilon(E)| = 1

    No core point can reach E, so it never receives a cluster id.

  4. Step 4 — the final labeling

    cluster 0={A,B,C,D},E1  (noise)\text{cluster } 0 = \{A, B, C, D\}, \qquad E \mapsto -1 \;(\text{noise})

    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?
Eps is the radius that defines a point's neighborhood, and minPts is how many points must fall within that radius for a region to count as dense. A point with at least minPts neighbors is a core point that seeds a cluster. Tuning these two values together is the main effort in getting DBSCAN to work well.
How do I pick a good value for eps?
A common heuristic is the k-distance plot: for each point compute the distance to its k-th nearest neighbor, sort those distances, and look for the elbow where they rise sharply. That elbow suggests a value separating dense interiors from sparse gaps. You should still try a few nearby values and inspect the results.
Why does DBSCAN label some points as noise?
Points that lie in low-density regions, meaning they lack enough nearby neighbors to belong to any dense cluster, are deliberately marked as noise rather than forced into a group. This is a feature, not a bug, because it makes DBSCAN useful for outlier and anomaly detection. If almost everything is noise, your eps is probably too small.
When should I use DBSCAN instead of K-Means?
Choose DBSCAN when clusters have irregular shapes, when you do not know how many clusters exist, or when you need to identify outliers. K-Means is better when you expect roughly spherical, similarly sized clusters and want speed on large data. DBSCAN struggles when clusters differ greatly in density.
Why does DBSCAN perform poorly on my high-dimensional data?
In high dimensions distances between points tend to become similar to one another, so the notion of a dense neighborhood loses meaning and a single eps no longer separates clusters from noise. Reducing dimensionality first, for example with PCA or UMAP, or using a density method suited to the data often helps.

Written & reviewed by the ML Visualization team · Last updated .