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.
- : the radius that defines a neighbourhood.
- : the whole dataset.
- : how many points that neighbourhood must contain.
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
- Pick an unvisited point and find every point within of it.
- If there are fewer than , mark it noise for now and move on.
- If there are enough, open a new cluster and add all of them to it.
- For each new member that is itself a core point, add its neighbourhood to the cluster too.
- 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
A common starting rule is twice the number of dimensions, with a floor at , and higher on noisy data.
For , compute each point's distance to its -th nearest neighbour where , 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 .
Where it fails
With a spatial index the run costs that much, and it degrades to in high dimensions where the index stops helping.
One 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.