DBSCAN Parameter Selection · Choosing Epsilon and MinPts

Choosing ε and minPts is the hardest part of using DBSCAN. This guide covers the standard method (k-distance graph) and practical heuristics.

The k-Distance Graph

The most widely recommended method:

  1. Set $k$ = minPts - 1
  2. For each point, compute the distance to its $k$-th nearest neighbour
  3. Sort all k-distances in descending order
  4. Plot the sorted k-distances
  5. The “elbow” or “knee” in this plot is a candidate ε
from sklearn.neighbors import NearestNeighbors
import numpy as np, matplotlib.pyplot as plt

k = 4  # minPts = 5
nbrs = NearestNeighbors(n_neighbors=k+1).fit(X)
distances, _ = nbrs.kneighbors(X)
k_dist = np.sort(distances[:, k])[::-1]
plt.plot(k_dist)
# Look for the elbow

The elbow corresponds to the transition from dense (within-cluster) to sparse (between-cluster) distances. Points to the left of the elbow are in clusters; points to the right are noise/inter-cluster.

Choosing minPts

Rule of thumb: minPts ≥ dimensionality + 1. For 2D data, minPts = 4. For higher-dimensional data, minPts ≥ 2 × dimensionality is safer due to the curse of dimensionality.

Practical approach: Set minPts to the smallest value that produces a clear elbow in the k-distance graph. If no elbow appears, increase minPts and replot. If multiple values produce clear elbows, choose the smallest (produces more, smaller clusters).

Automatic Knee Detection

For automated parameter selection, use kneed (KneeLocator) library to detect the elbow:

from kneed import KneeLocator
kneedle = KneeLocator(range(len(k_dist)), k_dist, S=1.0, curve='convex', direction='decreasing')
eps = k_dist[kneedle.knee]

The knee point can be sensitive to the smoothing parameter S. Visual inspection remains recommended for final parameter selection.

Validation Without Labels

Since you can’t use accuracy/F1 without labels, validate using:

  • Stability: Run DBSCAN with nearby ε values — are cluster assignments stable?
  • Domain coherence: Do the clusters make sense to a domain expert?
  • Noise rate: Is the noise proportion reasonable (5–15%)?