K-Means finds round clusters and forces every point into one. DBSCAN (Density-Based Spatial Clustering of Applications with Noise) instead finds clusters of any shape as dense regions separated by sparse regions, and labels isolated points as noise.

Parameters and Point Types

DBSCAN has two parameters. eps (ε) is the radius of a neighbourhood and minPts is the minimum number of points, counting the point itself, required in a neighbourhood for it to be dense. Every point is then one of three kinds:

  1. Core point: at least minPts points (including itself) lie within eps.
  2. Border point: fewer than minPts neighbours, but within eps of a core point.
  3. Noise point: neither core nor border.

The Algorithm

Pick an unvisited core point and start a new cluster. Add every point within eps; whenever a newly added point is also a core point, add its neighbours too, so the cluster grows by density reachability. When no more points can be added, the cluster is complete; move to the next unvisited core point. Points that remain unassigned are noise.

Strengths and Weaknesses

DBSCAN needs no value of k, finds arbitrary shapes, detects outliers and is little affected by them. Its drawbacks are that results are sensitive to eps and minPts, and that it struggles when clusters have very different densities and in high dimensions. A common way to pick eps is to plot the sorted distance to each point's k-th nearest neighbour and look for the knee.

Definition: DBSCAN. A clustering algorithm that groups points lying in dense regions, defined by a radius eps and a minimum number of points minPts, and marks points in sparse regions as noise.

Table 4.4: Point types in DBSCAN

Type Condition Role
Core At least minPts points within eps Grows the cluster
Border Within eps of a core point but not core Belongs to a cluster edge
Noise Neither core nor border Not in any cluster

Example 4.4: Clusters and noise

Problem: Points: (1,1), (1,2), (2,1), (2,2), (8,8), (8,9), (9,8), (9,9) and (5,15). With eps = 1.5 and minPts = 4, find the clusters and the noise.

Solution:

  1. Around (1,1) lie (1,2), (2,1) and (2,2), all within 1.5 (the farthest is 1.414). With itself that is 4 points, so (1,1) is a core point. The other three points of the group have the same count.
  2. The four points near (1,1) therefore form cluster 0. By the same argument (8,8), (8,9), (9,8) and (9,9) form cluster 1.
  3. The point (5,15) has no other point within 1.5, so it has only 1 point and is neither core nor border: noise.

Result: Two clusters of four points each, and one noise point.

from sklearn.cluster import DBSCAN
Q = [[1, 1], [1, 2], [2, 1], [2, 2], [8, 8], [8, 9], [9, 8],
     [9, 9], [5, 15]]
db = DBSCAN(eps=1.5, min_samples=4).fit(Q)
print("labels:", db.labels_.tolist())
n = len(set(db.labels_) - {-1})
print("clusters:", n, " noise points:", list(db.labels_).count(-1))

Output

labels: [0, 0, 0, 0, 1, 1, 1, 1, -1]
clusters: 2  noise points: 1

Common mistakes

  • Forgetting that minPts counts the point itself.
  • Using one eps for clusters of very different density.
  • Expecting every point to belong to a cluster; noise is allowed.
  • Not scaling the features before using a distance radius.

Key takeaways

  • Parameters: eps (radius) and minPts.
  • Core, border and noise points; label -1 means noise in scikit-learn.
  • Clusters grow by density reachability.
  • No k needed; finds arbitrary shapes; handles outliers.

Practice questions

  1. What are the two parameters of DBSCAN?
  2. What is a noise point?
  3. Name an advantage of DBSCAN over K-Means.

Answers to the practice questions

  1. eps, the neighbourhood radius, and minPts, the minimum number of points.
  2. A point that is neither a core point nor within eps of one.
  3. It needs no k, finds arbitrary shapes and detects outliers.

Sources

  • Official BCA syllabus Introduction to Machine Learning, course code 26BCA404DSE21, Unit IV