k-means needs to be told how many clusters to look for, and it always draws them as round, roughly equal-sized blobs. What about data that comes in two long, thin chains instead — and includes a point that doesn't belong to any group at all?
Two short chains of points, plus one point sitting far off on its own. Drag eps — the neighborhood radius — and watch clusters appear, merge, and disappear. Too small, and even points one unit apart look unrelated; too large, and two genuinely separate chains fuse into one.
DBSCAN — short for Density-Based Spatial Clustering of Applications with Noise — never asks how many clusters to expect. Instead, a point is a core point if it has enough neighbors within a radius eps:
- — whether point qualifies as a core point, based on how many neighbors it has.
- — two points in the dataset being compared.
eps— the neighborhood radius: how close two points must be to count as neighbors.minPts— the minimum number of neighbors withinepsneeded for a point to be a core point.
- Clusters grow by hopping between core points
A cluster is everything reachable by hopping from core point to core point, radius by radius — like a chain of falling dominoes, each one only needing to be close enough to knock over the next.
- Unreached points are noise
Anything never reached this way, from any core point, is noise — not assigned to any cluster at all.
At eps=0.5, even points exactly unit apart aren't neighbors — every point is isolated, and the whole dataset is noise. At eps=1.5, both chains connect internally without merging with each other. At eps=5.0, the two chains fuse into a single cluster — genuinely different structures, collapsed together by too generous a radius.
Two chains at and , points spaced unit apart within each chain, plus one point at :
- Checking a core point
Point has neighbors and , both at distance exactly — with
eps=1.5andminPts=1, that's enough: it's a core point. - The gap between chains
The closest pair across the two chains is and , at distance exactly . At
eps=1.5, that's nowhere close enough to connect — the chains stay two separate clusters. - The point with no neighbors at all
's nearest other point is : units away — far beyond any reasonable
eps. It's never a core point and never reachable from one, so DBSCAN correctly leaves it as noise, folded into neither cluster.
Find an eps that merges the two chains into a single cluster — without ever absorbing the far-off noise point.
DBSCAN trades k-means' two conveniences — pick up front, every point belongs to some cluster — for two things k-means can't do at all: clusters of any shape, and an explicit "doesn't belong anywhere" label for genuine outliers. Neither algorithm is strictly better; k-means assumes round, similarly-sized groups and gets a clean answer fast, while DBSCAN makes no shape assumption at all but needs eps tuned by hand, the same way itself did.