DBSCAN
eps
min_samples
clustering
machine learning

DBSCAN eps and min_samples

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a robust clustering algorithm that is particularly useful for identifying clusters of varying shapes and sizes in high-dimensional data. Unlike other clustering techniques like K-means, DBSCAN does not require specifying the number of clusters in advance. Instead, it relies on two key parameters: `eps` and `min_samples`.

Key `Parameters` of DBSCAN

1. `eps` (Epsilon)

`eps` is the maximum distance between two samples for them to be considered as part of the same neighborhood. It defines the radius of the neighborhood around a data point.

  • Technical Explanation: In the context of density-based clustering, the `eps` parameter determines the extent of the neighborhood. If the distance between any two data points is less than or equal to `eps`, they are considered neighbors.
  • Example: Consider a dataset with 2D points. If `eps` is set to 0.5, any two points within a Euclidean distance of 0.5 will be regarded as part of the same neighborhood.
  • Implications: Too small an `eps` value might lead to many small, fragmented clusters, while too large an `eps` value may result in merging distinct clusters together.

2. `min_samples`

`min_samples` is the minimum number of data points required to form a dense region. Essentially, it constitutes the threshold for core points.

  • Technical Explanation: A point is classified as a core point if it has at least `min_samples` points (including itself) within its `eps`-neighborhood.
  • Example: In a dataset where `min_samples` is set to 5, a point would need at least 4 other points within its `eps` radius to be classified as a core point.
  • Implications: A smaller `min_samples` can lead to many points being identified as core points, increasing the sensitivity of the algorithm to noise and potentially forming several small clusters. Conversely, a higher `min_samples` value may result in more points being classified as noise.

Understanding Core Points, Border Points, and Noise

  • Core Points: Have at least `min_samples` points within their `eps`-neighborhood.
  • Border Points: Are not core points themselves but are within the neighborhood of a core point.
  • Noise Points: Do not fall within the `eps`-neighborhood of any core points.

Algorithm Steps

  1. Select an initial point and check its `eps`-neighborhood.
  2. If it contains more than `min_samples`, consider it a core point and start forming a cluster.
  3. Expand the cluster by adding all directly connected points that meet the core point criteria.
  4. Repeat until all points have been visited.

Example Scenario

Suppose you have a dataset of points on a 2D plane. By setting `eps` to 1 and `min_samples` to 4, DBSCAN will classify points as core, border, or noise, and subsequently form clusters accordingly. A point with fewer than 4 neighboring points within one unit distance will be considered noise.

Practical Considerations

  • Parameter Selection: The choice of `eps` and `min_samples` is crucial and often requires experimentation. Using domain knowledge to estimate appropriate values can greatly enhance the quality of clustering.
  • Data Scaling: Ensuring that your data is normalized or standardized can also affect the performance of DBSCAN since it relies on distance measures.

Summary Table

ParameterDescriptionImplications
epsMaximum radius of the neighborhoodSmall eps: fragmented clusters, more noise Large eps: merged clusters
min\_samplesMinimum number of points to form a dense regionSmall min\_samples: more sensitivity to noise Large min\_samples: higher chance of noise

In summary, DBSCAN is an effective algorithm for clustering non-linear, dense regions, especially when outliers and varying cluster densities exist. Understanding and appropriately setting the `eps` and `min_samples` parameters is vital for achieving desirable clustering results. Experimentation and cross-validation are recommended strategies when applying DBSCAN to various datasets.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.