<jupyter_start><jupyter_text>Load digit dataset<jupyter_code>digits = load_digits()
X = np.array(digits.data)
y = np.array(digits.target)
X_scaled = scale(X)
X_reduced = PCA(n_components=2).fit_transform(X_scaled)<jupyter_output><empty_output><jupyter_text>Let's try sklearn's DBSCAN<jupyter_code>db = DBSCAN(eps=0.4, min_samples=14)
db.fit(X_reduced)
print('Estimated number of clusters: %d' % len(np.unique(db.labels_)))
print("Homogeneity: %0.3f" % homogeneity_score(y, db.labels_))
print("Completeness: %0.3f" % completeness_score(y, db.labels_))
print("V-measure: %0.3f" % v_measure_score(y, db.labels_))
print("Adjusted Rand Index: %0.3f"
      % adjusted_rand_score(y, db.labels_))
print("Adjusted Mutual Information: %0.3f"
      % adjusted_mutual_info_score(y, db.labels_))
print("Silhouette Coefficient: %0.3f"
      % silhouette_score(X_reduced, db.labels_))
num_cluster = len(np.unique(y))
unique_labels = set(db.labels_)
colors = [plt.cm.Spectral(each)
          for each in np.linspace(0, 1, len(unique_labels))]

core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True

for k, col in zip(unique_labels, colors):
    if k == -1:
        col = [0, 0, 0, 1]

    class_member_mask = (db.labels_ == k)

    xy = X_reduced[class_member_mask & core_samples_mask]
    plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
             markeredgecolor='k', markersize=14)

    xy = X_reduced[class_member_mask & ~core_samples_mask]
    plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
             markeredgecolor='k', markersize=6)

plt.title('Estimated number of clusters: %d' % len(np.unique(db.labels_)))
plt.show()<jupyter_output><empty_output><jupyter_text>Now our implementation<jupyter_code>db1 = dscan(eps=0.4, min_samples=13)
db1.fit(X_reduced)
print('Estimated number of clusters: %d' % len(np.unique(db1.labels_)))
print("Homogeneity: %0.3f" % homogeneity_score(y, db1.labels_))
print("Completeness: %0.3f" % completeness_score(y, db1.labels_))
print("V-measure: %0.3f" % v_measure_score(y, db1.labels_))
print("Adjusted Rand Index: %0.3f"
      % adjusted_rand_score(y, db1.labels_))
print("Adjusted Mutual Information: %0.3f"
      % adjusted_mutual_info_score(y, db1.labels_))
print("Silhouette Coefficient: %0.3f"
      % silhouette_score(X_reduced, db1.labels_))
palette = sns.color_palette("hls", num_cluster + 1)
_, ax = plt.subplots(figsize=(12, 8))

for i, index in enumerate(range(len(db1.clusters_))):
    point = np.array(X_reduced[db1.clusters_[index]]).T
    ax.scatter(*point, c=[palette[i], ])

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16080211880438894, 'fraction_numerical': 0.02345819144911086, 'mean_word_length': 5.659949622166247, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '540017', 'license': 'MIT', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1035, 'n_words': 173, 'path': 'DBSCAN/DBSCAN.ipynb', 'repo_name': 'nachiket273/ML_Algo_Implemented', 'size': '2643'}