OPTICS (Ordering Points To Identify the Clustering Structure) is a density-based clustering algorithm that produces an ordering of the data points together with a reachability distance for each point, from which clusters of varying density can be extracted. In machine learning, it generalizes DBSCAN: instead of committing to one neighborhood radius, it records the density structure for all radii up to a chosen maximum.
Introduced in 1999, OPTICS is valued for exploratory analysis, because its output, the reachability plot, shows nested and unevenly dense clusters at a glance. Like DBSCAN, it needs no preset number of clusters and labels sparse points as noise rather than forcing them into a group.
Core distance and reachability distance
OPTICS rests on two definitions. The core distance of a point is the distance to its MinPts-th nearest neighbor, provided that neighbor lies within the maximum radius epsilon; otherwise the point is not a core point and its core distance is undefined. A small core distance means the point sits in a dense region.
The reachability distance of point p from a core point o is the larger of the core distance of o and the actual distance between o and p. This smoothing step means points deep inside a dense cluster all receive roughly the same reachability value, which stabilizes the resulting plot.
The table below summarizes the quantities that OPTICS computes and stores.
| Quantity | Definition | Role in the algorithm |
|---|---|---|
| Epsilon neighborhood | All points within radius epsilon | Bounds the search and the cost |
| Core distance | Distance to the MinPts-th neighbor within epsilon | Measures local density |
| Reachability distance | Max of core distance and pairwise distance | Value plotted for each point |
| Ordering | Sequence in which points are processed | Places cluster members next to each other |
How the OPTICS ordering is built
The algorithm processes points one at a time and always expands next to the closest reachable point, using a priority queue called the seed list. When a core point is processed, every unprocessed neighbor within epsilon is inserted or has its reachability value lowered if a smaller value is found.
- Pick an unprocessed point, mark it processed and append it to the ordering.
- If it is a core point, update the reachability of its neighbors in the seed list.
- Take the seed with the smallest reachability, process it and repeat step 2.
- When the seed list is empty, start again from another unprocessed point.
Because expansion always follows the densest path, each cluster appears as a contiguous run in the ordering. With a spatial index, the runtime is about O(n log n); without one, neighborhood queries make it O(n squared), and memory for pairwise distances can become the limiting factor.
Reading the reachability plot and extracting clusters
The reachability plot draws the ordering on the horizontal axis and the reachability distance on the vertical axis. Valleys correspond to clusters, deeper valleys mean denser clusters, and tall peaks mark the gaps between them. A valley nested inside a wider valley reveals a hierarchical cluster structure.
Two extraction methods turn the plot into labels:
| Method | How it works | Result | Best for |
|---|---|---|---|
| DBSCAN-style cut | Horizontal threshold at a chosen radius | Flat clusters equal to DBSCAN at that radius | Quick, single-density data |
| Xi method | Detects steep downward and upward slopes by a relative factor xi | Hierarchical clusters of varying density | Uneven densities |
| Manual inspection | Analyst reads valleys in the plot | Interpretable grouping | Exploratory studies |
The xi parameter, typically between 0.01 and 0.1, sets how steep a drop must be to start a cluster. Smaller values detect subtler clusters but also fragment noisy data.
OPTICS compared with DBSCAN, HDBSCAN and k-means
OPTICS belongs to the density-based family, and its practical value is clearest beside its neighbors. Its distinguishing feature is that the expensive work is done once, and clusterings for many density levels can then be read off without rerunning the algorithm.
| Algorithm | Key parameters | Handles varying density | Output |
|---|---|---|---|
| OPTICS | MinPts, optional epsilon, xi | Yes | Ordering and reachability plot |
| DBSCAN | MinPts and epsilon | No | Flat labels with noise |
| HDBSCAN | Minimum cluster size | Yes | Stable flat labels and a hierarchy |
| k-means | Number of clusters k | No | Flat labels, no noise |
| Hierarchical clustering | Linkage and cut height | Partly | Dendrogram |
In many current projects HDBSCAN replaces OPTICS for automatic labeling, because it selects stable clusters without a slope parameter. OPTICS remains preferred when analysts want the visual density profile itself.
Choosing parameters and avoiding common mistakes
MinPts controls smoothing: a common starting point is twice the number of dimensions, with at least 5. Setting epsilon to infinity gives the full structure at higher cost, while a finite epsilon speeds the run but may cut off sparse clusters.
The distance metric matters as much as the parameters. Euclidean distance suits continuous, scaled features, while haversine distance fits geographic coordinates and cosine distance fits text embeddings. Points whose reachability remains undefined or very high at the end of the run are best treated as noise or outliers, and many teams use that property for lightweight anomaly screening. Results also depend slightly on processing order among equal reachability values, so border points can switch between neighboring clusters across implementations.
- Unscaled features: distances are dominated by large-range variables, so apply feature scaling first.
- High dimensionality: the curse of dimensionality flattens distances and erases valleys; reduce dimensions beforehand.
- Too small MinPts: the plot becomes jagged and the xi method produces spurious clusters.
- Misreading the order: positions on the horizontal axis are not coordinates, only a processing sequence.
Understanding it simply
Imagine walking through a city at night and always stepping toward the nearest lit window. Inside a busy neighborhood, every step is short. When you leave it, you must take a long step to reach the next group of houses.
OPTICS walks through data in the same way and writes down the length of each step. Short steps in a row mean a crowded group of points. A sudden long step means the walk has left one group and reached another. Drawing the step lengths as a chart shows every group as a valley, even when some groups are crowded and others are loose.
Applied in practice
A logistics analyst studies two years of delivery locations for a regional courier to find natural service zones. The city center has extremely dense drop-off points, while suburbs and villages are spread thinly. A DBSCAN run with one radius either merges the whole center into one blob or labels most villages as noise.
The analyst runs OPTICS on projected coordinates in meters with MinPts set to 20. The reachability plot shows deep, narrow valleys for downtown districts and broad, shallow valleys for suburban towns. Using the xi method with xi of 0.05, the analyst extracts zones at both scales in one pass. The courier then redraws its route zones to follow these density-based groups.