How DBSCAN grows a density cluster

Short answer: DBSCAN grows clusters from core points. A core point has at least minPts points, including itself, inside radius ε. A cluster is a core point plus every point density-reachable from it through a chain of cores. Points that are within ε of a cluster and are not themselves cores are border points. Everything else is noise. The algorithm needs no preset number of clusters. With a spatial index a run is about O(n log n).


What the problem actually asks

k-means wants blobs around means and wants k. DBSCAN wants regions where points are packed at least minPts deep inside every ball of radius ε, and it wants the noise points left unlabeled. The reachability definition prevents a sparse bridge of non-core points from gluing two dense regions together, because a border point does not extend the cluster further.

The parameters ε and minPts are the model. A too-large ε merges clusters. A too-small ε labels everything as noise. minPts is often set near twice the dimension or a little higher, and ε is chosen from a k-distance plot. Neither choice is free of the data.


What the algorithm guarantees

The partition into clusters, border points, and noise is defined by ε and minPts, and a standard implementation computes it in one pass over the cores. Border points that are reachable from two clusters are assigned to whichever cluster is expanded first, so that detail of the labeling depends on order. The cores’ cluster membership does not. Time is O(n²) with a linear neighbor search and about O(n log n) with a range tree or a grid when the data allow it.

The algorithm uses a symmetric distance. A density that varies across the set, clusters inside clusters at different scales, defeats a single ε. OPTICS and HDBSCAN are the relatives that address variable density. DBSCAN does not place a center and does not minimize a squared-error objective.


The working steps

  1. For each point, find the neighbors inside radius ε. Mark the point as core if the neighbor count is at least minPts.
  2. Visit each unvisited core. Start a cluster and expand a queue through every core neighbor, adding the density-reachable cores and their neighbor points.
  3. A non-core neighbor is a border point of this cluster and is not used to expand further.
  4. Points never reached are noise.
  5. Choose ε from the data, often by inspecting the distance to the minPts-th neighbor, rather than by guessing a coordinate unit.

A single global ε assumes one density scale. k-means assumes blobs and a known k. DBSCAN assumes neither, and it assumes the distance and ε match the scale of the clusters the caller cares about. Border-point assignment can depend on expansion order. Core membership does not.


Approaches that look simpler and fail

Approach Why it fails when a border point is allowed to recruit new members
Expand the cluster through every neighbor, core or not A chain of border points can connect two dense regions the definition keeps separate. Only cores expand the cluster.
Set ε once for a data set whose clusters have different scales One radius cannot be inside the tight cluster and inside the loose cluster at the same time. The single-ε definition will merge, split, or mark noise.
Replace the neighbor count by a k-means objective The algorithms optimize different criteria. A low squared error is not a DBSCAN cluster.
Forget the spatial index and quote O(n log n) The log factor comes from the neighbor search. A linear scan of all points for each query is quadratic.

A preset number of spherical clusters is k-means. A hierarchy of densities is OPTICS or HDBSCAN. DBSCAN is the single-ε density clustering with core and border points.


A working example

This Python fragment marks a point as a core when at least minPts points, counting itself, lie inside ε, and only cores expand a cluster. With ε = 1.5 and minPts = 2, the pairs (0, 0),(1, 0) and (5, 5),(6, 5) are two clusters and (10, 0) is noise. It prints 2.

import math
pts = [(0, 0), (1, 0), (5, 5), (6, 5), (10, 0)]
eps, min_pts = 1.5, 2

def neighbors(i):
    return [j for j, q in enumerate(pts) if math.hypot(pts[i][0] - q[0], pts[i][1] - q[1]) <= eps]

labels = [-1] * len(pts)
cluster = 0
for i in range(len(pts)):
    if labels[i] != -1:
        continue
    nbrs = neighbors(i)
    if len(nbrs) < min_pts:
        continue
    labels[i] = cluster
    stack = nbrs[:]
    while stack:
        j = stack.pop()
        if labels[j] == -1:
            labels[j] = cluster
            more = neighbors(j)
            if len(more) >= min_pts:
                stack.extend(more)
        elif labels[j] < 0:
            labels[j] = cluster
    cluster += 1
assert cluster == 2 and labels[-1] == -1
print(cluster)

Where it is used

scikit-learn‘s DBSCAN groups GPS points and other spatial samples by density and leaves outliers unlabeled. Customer locations and anomaly clumps are the usual input. K-means forces every point into a cluster and asks for the number of clusters first.


When you can drop this algorithm

Drop a single ε when the clusters visibly live at several densities. Use a hierarchical density method. Keep DBSCAN when one density scale, a distance, and an explicit noise label match the data.


Why this stays published

We publish this so a search for DBSCAN returns the core-point rule and the reason border points do not expand a cluster. DBSCAN forms a cluster by expanding through core points that have at least minPts neighbors inside radius ε, and it leaves the remaining points as border or noise.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *