DOC Update notebook-style example plot_dbscan
@@ -16,8 +16,9 @@ from sklearn.datasets import make_blobs
from sklearn.preprocessing import StandardScaler
-# #############################################################################
+# %%
# Generate sample data
+# --------------------
centers = [[1, 1], [-1, -1], [1, -1]]
X, labels_true = make_blobs(
n_samples=750, centers=centers, cluster_std=0.4, random_state=0
@@ -25,8 +26,9 @@ X, labels_true = make_blobs(
X = StandardScaler().fit_transform(X)
-# #############################################################################
+# %%
# Compute DBSCAN
+# --------------
db = DBSCAN(eps=0.3, min_samples=10).fit(X)
core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
@@ -48,8 +50,9 @@ print(
)
print("Silhouette Coefficient: %0.3f" % metrics.silhouette_score(X, labels))
-# #############################################################################
+# %%
# Plot result
+# -----------
import matplotlib.pyplot as plt
# Black removed and is used for noise instead.
