<jupyter_start><jupyter_text>PCA(0.95) 代表获取主成分的维度个数能解释 95%的方差<jupyter_code>pca = PCA(0.95)
pca.fit(X_train)
# 此时前28个维度就可以解释95%的方差
pca.n_components_
X_train_reduction = pca.transform(X_train)
X_test_reduction = pca.transform(X_test)
%%time
knn = KNeighborsClassifier()
knn.fit(X_train_reduction, y_train)
knn.score(X_test_reduction, y_test)
pca = PCA(n_components=2)
pca.fit(X)
X_reduction = pca.transform(X)
X_reduction.shape
for i in range(10):
    plt.scatter(X_reduction[y==i, 0], X_reduction[y==i, 1], alpha=0.8)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1436265709156194, 'fraction_numerical': 0.03411131059245961, 'mean_word_length': 8.457627118644067, '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': '387246', 'license': 'MIT', 'n_tokens_mistral': 293, 'n_tokens_neox': 278, 'n_words': 34, 'path': 'ml/pca/PCA-IN-SCIKIT-LEARN.ipynb', 'repo_name': 'tangchunbo/machine-learning', 'size': '557'}