Ordering Points To Identify Cluster Structure (OPTICS) using Sklearn (original) (raw)

`space = np.arange(len(X_modified)) reachability = clust.reachability_[clust.ordering_] labels = clust.labels_[clust.ordering_]

plt.figure(figsize=(10, 7)) G = gridspec.GridSpec(2, 3) ax1 = plt.subplot(G[0, :]) ax2 = plt.subplot(G[1, 0]) ax3 = plt.subplot(G[1, 1]) ax4 = plt.subplot(G[1, 2])

Reachability Plot

colors = ["b.", "g.", "r.", "y.", "c."] for klass, color in zip(range(0, 5), colors): Xk = space[labels == klass] Rk = reachability[labels == klass] ax1.plot(Xk, Rk, color, alpha=0.3) ax1.plot(space[labels == -1], reachability[labels == -1], "k.", alpha=0.3) ax1.plot(space, np.full_like(space, 1.5, dtype=float), "k-", alpha=0.5) ax1.plot(space, np.full_like(space, 0.8, dtype=float), "k-.", alpha=0.5) ax1.set_ylabel("Reachability (epsilon distance)") ax1.set_title("Reachability Plot")

OPTICS Clustering Result

colors = ["b.", "g.", "r.", "y.", "c."] for klass, color in zip(range(0, 5), colors): Xk = X_modified[clust.labels_ == klass] ax2.plot(Xk[:, 0], Xk[:, 1], color, alpha=0.3) ax2.plot(X_modified[clust.labels_ == -1, 0], X_modified[clust.labels_ == -1, 1], "k+", alpha=0.1) ax2.set_title("Automatic Clustering\nOPTICS")

DBSCAN Result at eps = 0.7

colors = ["b.", "g.", "r.", "c."] for klass, color in zip(range(0, 4), colors): Xk = X_modified[labels_050 == klass] ax3.plot(Xk[:, 0], Xk[:, 1], color, alpha=0.3) ax3.plot(X_modified[labels_050 == -1, 0], X_modified[labels_050 == -1, 1], "k+", alpha=0.1) ax3.set_title("Clustering at 0.7 epsilon cut\nDBSCAN")

DBSCAN Result at eps = 1.5

colors = ["b.", "m.", "y.", "c."] for klass, color in zip(range(0, 4), colors): Xk = X_modified[labels_200 == klass] ax4.plot(Xk[:, 0], Xk[:, 1], color, alpha=0.3) ax4.plot(X_modified[labels_200 == -1, 0], X_modified[labels_200 == -1, 1], "k+", alpha=0.1) ax4.set_title("Clustering at 1.5 epsilon cut\nDBSCAN")

plt.tight_layout() plt.show()

`