OPTICS Clustering
DBSCAN's blind spot: one density for the whole dataset
DBSCAN clusters points using two fixed parameters: eps (the neighborhood radius) and min_samples (how many neighbors make a point "dense"). This works well when all real clusters in the data have roughly the same density. But real data often has clusters of very different densities — a tight cluster of 50 points packed into a small region, and a loose cluster of 50 points spread across a much larger one.
With a single global eps, DBSCAN cannot handle both well simultaneously: an eps small enough to resolve the tight cluster will fail to connect the loose cluster's points at all, while an eps large enough to connect the loose cluster will merge the tight cluster into its neighbors. OPTICS (Ordering Points To Identify the Clustering Structure) was designed specifically to fix this.
Reachability distance: the core new idea
OPTICS doesn't partition data directly into clusters. Instead, it computes an ordering of all points and, for each point, a reachability distance — roughly, how far you'd have to extend a neighborhood radius to density-reach that point from the nearest already-processed dense point. Formally, the reachability distance of point *p* from point *o* is the larger of: the core distance of *o* (the radius needed for *o* to have min_samples neighbors), and the actual distance between *o* and *p*.
OPTICS then processes points in order of increasing reachability distance, similar to Prim's algorithm for minimum spanning trees, building an ordering where points in the same dense region end up adjacent to each other in the sequence.
The reachability plot: clusters as valleys
The output of OPTICS is best understood visually: plot each point's reachability distance against its position in the computed ordering. Dense clusters show up as valleys — runs of points with low reachability distance, because they're close to their neighbors in the ordering. Gaps between clusters show up as peaks — sharp spikes in reachability distance where you jump from one dense region to a different one.
Crucially, valleys of different depths represent clusters of different densities, all visible in the same plot. You can extract flat clusters from this structure using a variable threshold, or an automated method like the xi extraction algorithm, without having to pick one global density cutoff in advance.
Note
eps would do. OPTICS is strictly more informative: it computes the full ordering once, and you can extract clusterings at multiple density thresholds afterward without rerunning the core algorithm, which is useful for exploring data where the right density cutoff isn't known in advance.DBSCAN vs. OPTICS
| Dimension | DBSCAN | OPTICS |
|---|---|---|
| Density assumption | Single global density threshold | Handles varying density clusters |
| Output | Direct cluster labels | An ordering + reachability plot, clusters extracted after |
| Parameters | eps, min_samples (eps is sensitive) | min_samples, xi (no fixed eps required) |
| Computational cost | Lower — one pass with fixed eps | Higher — effectively explores a range of eps values |
| Best for | Roughly uniform-density clusters | Mixed-density real-world data |
Note
min_samples still strongly shapes the reachability plot — too small and noise looks like clusters, too large and small genuine clusters get smoothed away or marked as noise. Try a few values and inspect the resulting reachability plot visually rather than trusting the first result.Contrast: how K-Means handles the same data (for comparison)
📊 K-Means Clustering Simulator
InteractiveWhat's next
OPTICS generalizes density-based clustering, but another family of algorithms takes a completely different route to the same goal — letting data points "vote" for their own exemplars through message passing. The next lesson covers Affinity Propagation.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.