Sub topic 14
Where DBSCAN struggles
This chapter assumes you know how DBSCAN defines core, border, and noise points, and what eps and min_samples control. It covers the situations where those definitions stop working and what to do about each.
One density threshold for the whole dataset
DBSCAN applies a single eps and a single min_samples everywhere. If your clusters have different densities, no one setting fits all of them.
- A small
epssuits the dense cluster, but points in the sparse cluster fail the core test and become noise. - A large
epscaptures the sparse cluster, but the dense cluster grows into its neighbors and merges with them.
The code below shows both effects on two blobs of very different spread.
import numpy as np
from sklearn.cluster import DBSCAN
from sklearn.datasets import make_blobs
X, _ = make_blobs(
n_samples=[200, 200],
centers=[[0, 0], [6, 0]],
cluster_std=[0.3, 1.2],
random_state=0,
)
for eps in [0.2, 0.4, 0.8, 1.5]:
labels = DBSCAN(eps=eps, min_samples=5).fit_predict(X)
n_clusters = len(set(labels)) - (1 if -1 in labels else 0)
n_noise = int(np.sum(labels == -1))
print(f"eps={eps}: clusters={n_clusters}, noise={n_noise}")Expect many noise points at small eps. At large eps the cluster count drops as separate groups join. No value gives a clean split of both blobs. Methods that vary the density threshold, such as OPTICS and HDBSCAN, handle this case better.
Sensitivity to eps
Small changes in eps can change the result sharply. Moving it slightly can turn a thin bridge of points between two clusters into a connection, and the clusters then merge. The k-distance plot gives a starting value, but you should check nearby values and confirm the labels are stable.
High-dimensional data
In many dimensions, distances between points become similar to each other. The gap between "near" and "far" shrinks, so an eps that separates dense from sparse regions is hard to find. Most points then end up all noise or all one cluster. Euclidean distance is the usual cause. Reduce dimensions first (for example with PCA), or use a distance suited to your data.
Scaling and the choice of metric
eps is a distance, so its meaning depends on feature units. A feature measured in thousands dominates one measured in fractions. Scale features before running DBSCAN, as you did in the practical chapter.
Border points depend on order
A border point lies within eps of core points from two different clusters. DBSCAN assigns it to whichever cluster reaches it first, which depends on the row order of your data. Core and noise labels are deterministic. Only border assignments can change when you shuffle the rows.
Cost on large datasets
With a spatial index (k-d tree or ball tree) and a small eps, neighbor queries are fast. With high dimensions or a large eps, queries approach brute force, and time grows roughly with the square of the number of points. Memory also grows, because each point stores its neighbor list.
Summary of failure modes
| Problem | Symptom | Common remedy |
|---|---|---|
| Varying density | Sparse clusters become noise, or dense ones merge | OPTICS or HDBSCAN |
| Sensitive `eps` | Results change with small parameter shifts | Scan a range of values, check stability |
| High dimensions | Everything is noise or one cluster | Reduce dimensions, change the metric |
| Unscaled features | One feature controls the distances | Standardize first |
| Border ties | Labels change when rows are shuffled | Treat border labels as approximate |
Exercise
Your data has one tight cluster and one loose cluster. With eps=0.3, the loose cluster is almost entirely labeled -1. You raise eps to 1.5, and the tight cluster merges with a third group nearby. Why does this happen, and what method would you try next?
Show answer
DBSCAN uses one eps for all points. A value small enough to keep the tight cluster separate is too small for the loose cluster's points to have min_samples neighbors, so they become noise. A value large enough for the loose cluster is too large for the dense region, so nearby groups join. Try OPTICS or HDBSCAN, which handle clusters of varying density.