What Is DBSCAN Clustering? A Density-Based Guide for Beginners

Updated · By Viviai

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.

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.

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

  1. Pick an unvisited point and find all points within eps.
  2. If the neighborhood holds at least min_samples points, mark the point as a core point and start a new cluster.
  3. Add every point in the neighborhood to the cluster. When another core point appears, expand into its neighborhood as well.
  4. 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.
  5. 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

For more context, read about what is clustering, k-means clustering, and unsupervised learning.

Sources

  1. https://scikit-learn.org/stable/modules/clustering.html
  2. http://www.shturl.cc/7c8ddb7137bf2ffaf3365ad5dcdcf620
  3. https://mhahsler.r-universe.dev/dbscan/doc/dbscan_paper_vignette.pdf
  4. https://cse.buffalo.edu/~jing/cse601/fa13/materials/clustering_density.pdf

Learn by doing

Read a guide, then practice with bite-sized AI lessons you can take offline.

Start learning free