What Is DBSCAN Clustering? A Density-Based Guide for Beginners
DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is an unsupervised clustering algorithm that groups points that sit close together in dense regions while marking isolated points in sparse areas as noise. Unlike k-means, it does not need the number of clusters set in advance and can find clusters of irregular, non-spherical shapes. It was proposed by Martin Ester, Hans-Peter Kriegel, Jörg Sander, and Xiaowei Xu in 1996 and received the ACM SIGKDD Test of Time Award in 2014.
The core idea: dense regions, not round blobs
Many clustering methods, including k-means, assume each cluster looks like a compact, roughly convex blob around a center. Real data is often messier: clusters can curve, wrap around each other, or contain stray points.
DBSCAN takes a different view. It treats a cluster as a connected region where points are packed densely, separated from other clusters by areas of low density. Any point that does not belong to a dense region is treated as noise rather than forced into a cluster. This is why the same algorithm can handle both oddly shaped clusters and outliers.
The two parameters: eps and min_samples
DBSCAN needs just two parameters to define what "dense" means.
| Parameter | Meaning | Role |
|---|---|---|
| eps (ε) | Radius of the neighborhood around a point | Sets how close points must be to count as neighbors |
| min_samples (MinPts) | Minimum points within eps for a point to be a core point | Sets how dense a region must be |
The scikit-learn documentation notes that a higher min_samples or a lower eps raises the density required to form a cluster. Tuning these two values controls whether the algorithm finds many small clusters or a few broad ones.
Three types of points
As the algorithm runs, every point falls into one of three categories.
- Core point: A point whose eps neighborhood contains at least
min_samplespoints (including itself). Core points sit in the dense interior and drive cluster growth. - Border point: A point that is not a core point itself but lies within the eps neighborhood of a core point. It joins the cluster as an edge member.
- Noise point: A point that is neither a core point nor reachable from one. It stays unassigned and is labeled as noise.
The distinction matters because border points can look almost as isolated as noise, but they are anchored to a core point, while noise points are not.
Density reachability and connectivity
The formal definitions describe how points link into the same cluster.
- Directly density-reachable: Point
qis directly reachable from a core pointpifqlies within eps ofp. - Density-reachable: A point is reachable through a chain of directly reachable core points.
- Density-connected: Two points are connected when some core point can reach both of them.
A cluster is then the set of all density-connected points, expanded from its core points, while points outside every such set are noise.
How the algorithm works step by step
- Pick an unvisited point and find all points within eps.
- If the neighborhood holds at least
min_samplespoints, mark the point as a core point and start a new cluster. - Add every point in the neighborhood to the cluster. When another core point appears, expand into its neighborhood as well.
- If the first point is not a core point, label it temporarily as noise; it may later be picked up as a border point of another cluster.
- Repeat until every point has been visited.
Because each cluster grows outward from core points, the number of clusters emerges from the data instead of being chosen beforehand.
How to choose eps: the k-distance graph
A common way to estimate eps is the k-distance graph. For each point, compute the distance to its k-th nearest neighbor (with k often set near min_samples), sort these distances, and plot them. The distances rise slowly for points inside dense regions and jump for points near sparse areas. The bend, or elbow, where the curve starts rising sharply is a useful candidate for eps.
Features should be scaled before this step, because eps is a distance and a feature with a large numeric range would otherwise dominate the result.
DBSCAN vs k-means
| Aspect | DBSCAN | k-means |
|---|---|---|
| Number of clusters | Determined from data | Must be set in advance |
| Cluster shape | Arbitrary, connected regions | Assumes convex, compact clusters |
| Outliers | Identifies them as noise | Assigns every point to a cluster |
| Sensitivity | eps and min_samples | Initial centers and scaling |
| Weakness | Varying density, high dimensions | Non-spherical data, outliers |
Strengths and limitations
DBSCAN works without a preset cluster count, separates noise from meaningful structure, and can follow clusters of varied shapes. On the other hand, it is sensitive to the choice of eps and min_samples, and it struggles when clusters have different densities, because a single eps value cannot suit all of them. In high-dimensional spaces, distances become less informative and the method can lose its edge. For varying density, the hierarchical extension HDBSCAN adapts without relying on one fixed eps.
FAQ
Does DBSCAN require the number of clusters in advance?
No. It forms clusters from connected dense regions and decides the number based on the data and the two parameters.
What is the difference between a border point and a noise point?
A border point is reachable from a core point and joins that cluster. A noise point is not a core point and is not reachable from one, so it remains unassigned.
When does DBSCAN tend to struggle?
When clusters have uneven densities, when eps and min_samples are poorly matched, and in high-dimensional data where distances are less reliable.
What is HDBSCAN?
A hierarchical extension that lets the effective density vary across the data, removing the need for a single eps value.
Key takeaways
- DBSCAN clusters connected dense regions and labels sparse, isolated points as noise.
- The two parameters eps and min_samples define density.
- Core points expand clusters; border points attach to them; noise points stay out.
- The k-distance graph helps estimate eps, and features should be scaled first.
For more context, read about what is clustering, k-means clustering, and unsupervised learning.
Sources
Learn by doing
Read a guide, then practice with bite-sized AI lessons you can take offline.
Start learning free