<jupyter_start><jupyter_text><jupyter_code>import numpy as np
from sklearn.datasets import load_digits
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from sklearn.metrics import confusion_matrix
import seaborn as sns
from scipy.optimize import linear_sum_assignment as linear_assignment
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape(len(X_train), -1)
X_train = X_train.astype(np.float32) / 255
kmeans = KMeans(init="random", n_clusters=10, n_init=4, random_state=0)
kmeans.fit(X_train, y_train)
cm = confusion_matrix(y_train, kmeans.labels_)
sns.set()
ax = sns.heatmap(cm, annot=True, fmt="d", cmap="Blues")
def _make_cost_m(cm):
    s = np.max(cm)
    return (- cm + s)

_, col_ind = linear_assignment(_make_cost_m(cm))
cm2 = cm[:, col_ind]
ax = sns.heatmap(cm2, annot=True, fmt="d", cmap="Blues")
np.trace(cm2) / np.sum(cm)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12474645030425964, 'fraction_numerical': 0.013184584178498986, 'mean_word_length': 6.534351145038168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '206366', 'license': 'MIT', 'n_tokens_mistral': 402, 'n_tokens_neox': 387, 'n_words': 84, 'path': 'MNIST-k-means-1.ipynb', 'repo_name': 'diaboloshogunate/GoogleColabML', 'size': '986'}