Skip to content

Understanding OPTICS Clustering

OPTICS (Ordering Points To Identify the Clustering Structure) is an algorithm for finding density-based clusters in spatial data. It's similar to DBSCAN but addresses some of its shortcomings, such as the need to specify a global density threshold.

Advantages of OPTICS

  • Deals with Varying Density: Unlike DBSCAN, OPTICS can identify clusters of varying density, as it does not require a global density threshold.

  • Hierarchical Clustering: OPTICS creates a reachability plot, which can be used to extract a hierarchical clustering structure.

  • Less Sensitive to Parameters: OPTICS requires two parameters, min_samples and max_eps, but it is less sensitive to the choice of max_eps compared to DBSCAN's eps.

  • Outlier Detection: The algorithm can detect outliers as points that are not included in any cluster.

OPTICS Reachability Plot An example of a reachability plot generated by the OPTICS algorithm.

Disadvantages of OPTICS

  • Higher Computational Complexity: OPTICS is computationally more expensive than DBSCAN, especially for large datasets.

  • Complexity of Parameter Selection: Although less sensitive, choosing the correct min_samples can still be challenging.

  • Interpretation of Results: The reachability plot and the extracted clustering structure can be difficult to interpret, especially for those unfamiliar with the algorithm.

Sample Code

Here's an example of how to use the OPTICS clustering algorithm with Python's scikit-learn library:

from sklearn.cluster import OPTICS
import numpy as np
import matplotlib.pyplot as plt

# Sample data
X = np.array([[1, 2], [2, 5], [3, 6], [8, 7], [8, 8], [7, 3]])

# Run OPTICS
optics = OPTICS(min_samples=2, max_eps=np.inf)
optics.fit(X)

# Reachability plot
reachability = optics.reachability_[optics.ordering_]
plt.figure(figsize=(10, 4))
plt.bar(range(len(reachability)), reachability)
plt.title('Reachability Plot')
plt.xlabel('Points (ordered)')
plt.ylabel('Reachability Distance')
plt.show()

# Plot clusters
space = np.arange(len(X))
reachability = optics.reachability_[optics.ordering_]
labels = optics.labels_[optics.ordering_]

plt.figure(figsize=(10, 7))
G = space[labels == -1]
R = space[labels != -1]

plt.bar(G, reachability[G], color='r', label='Noise')
plt.bar(R, reachability[R], color='b', label='Clustered')
plt.legend()
plt.title('OPTICS Clustering')
plt.xlabel('Points (ordered)')
plt.ylabel('Reachability Distance')
plt.show()

Scenarios for Using OPTICS

  • Spatial Data Analysis: When working with geographical or spatial data where clusters may have varying densities.

  • Large Datasets: For larger datasets where the hierarchical structure may be of interest.

  • Complex Data Structures: When the data contains complex structures and noise, making it difficult for algorithms like K-means or DBSCAN to find the true clusters.

Remember, OPTICS is best suited for situations where the density variation within the dataset is significant, and the user is interested in identifying a hierarchical clustering structure. It is less effective for high-dimensional data due to the "curse of dimensionality," and it may not be the best choice for very large datasets due to its computational cost.