Density clustering with DBSCAN
Quick answer
DBSCAN finds dense connected groups without requiring a preset cluster count. It uses a neighborhood radius eps and a minimum neighborhood size to identify core points, border points and noise. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Count inclusive neighborhoods
x=[0,1,2,10]counts=[sum(abs(v-z)<=1 for z in x) for v in x]print(counts,[i for i,n in enumerate(counts) if n>=3])Observed local output:
[2, 3, 2, 1] [1]The middle point alone reaches the core threshold.
How it works
Define N_eps(p) as observations at distance <= eps from p, including p itself. A core point has at least min_samples neighbors (unweighted case). A non-core point within eps of a core point can be assigned as a border point. Remaining points are noise, represented by -1 in scikit-learn. Connected core neighborhoods form the backbone of a cluster. Border points reachable from more than one group can have assignment dependent on traversal order. On scalar points [0,1,2,10], eps=1 and min_samples=3, point 1 has three neighbors and is core; 0 and 2 are borders, and 10 is noise. A larger eps may merge distinct groups, while too small a radius can label almost everything noise. A single global radius may be unsuitable when densities differ; OPTICS or HDBSCAN are candidate alternatives for further study. Distance units matter: rescaling one coordinate can change every neighborhood. For Euclidean geometry, select eps in the transformed feature units. DBSCAN does not define a general native predict method for unseen rows; refitting on new data can change groups and IDs. Its noise flag reflects local density relative to the chosen parameters, not proof of an anomaly or a label of wrongdoing. Neighborhood materialization can consume quadratic memory in dense worst-case settings.
Inspect noise and core membership
from sklearn.cluster import DBSCANm=DBSCAN(eps=1,min_samples=3).fit([[0],[1],[2],[10]])print(m.labels_.tolist(),m.core_sample_indices_.tolist())Observed local output:
[0, 0, 0, -1] [1]The first three rows are density connected; the distant point is noise.
Common mistakes
Remember the point counts itself and the boundary is inclusive. Do not assume -1 is an ordinary discovered cluster or a confirmed anomaly. Do not discard noise before reporting coverage. Do not present refit cluster IDs as a stable production assignment contract.
Practice and next steps
For points [0,1,2,6], radius 1 and min_samples 2, count each neighborhood and determine core points. Then increase min_samples to 3 and explain which roles change. Complete the knowledge check and staged exercise. Next: Gaussian mixtures and EM.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Density clustering with DBSCAN — knowledge check
Apply density clustering with dbscan to new scenarios.
Does min_samples count the point itself?
What does -1 mean in scikit-learn DBSCAN?
What can a radius that is too large do?
What is a border point?
Does noise prove an anomaly?