<jupyter_start><jupyter_text>MNIST<jupyter_code>import numpy as np
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original', data_home='../data')
mnist
X, y = mnist['data'], mnist['target']
X.shape
y.shape
X_train = np.array(X[:60000], dtype=float)
y_train = np.array(y[:60000], dtype=float)
X_test = np.array(X[60000:], dtype=float)
y_test = np.array(y[60000:], dtype=float)
X_train.shape<jupyter_output><empty_output><jupyter_text>使用KNN<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
%time knn.fit(X_train, y_train)
%time knn.score(X_test, y_test)<jupyter_output>Wall time: 12min 38s<jupyter_text>PCA降维度<jupyter_code>from sklearn.decomposition import PCA
pca = PCA(0.9)
pca.fit(X_train)
X_train_reduction = pca.transform(X_train)
X_test_reduction = pca.transform(X_test)
X_train_reduction.shape
knn = KNeighborsClassifier()
%time knn.fit(X_train_reduction, y_train)
%time knn.score(X_test_reduction, y_test)<jupyter_output>Wall time: 1min 7s
{'fraction_non_alphanumeric': 0.12944664031620554, 'fraction_numerical': 0.02766798418972332, 'mean_word_length': 9.029702970297029, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '510003', 'license': 'MIT', 'n_tokens_mistral': 458, 'n_tokens_neox': 424, 'n_words': 68, 'path': 'ml/pca/PCA-MNIST.ipynb', 'repo_name': 'tangchunbo/machine-learning', 'size': '1012'}