Neural Sync Active
PCA and t-SNE
Registry Synced
PCA and t-SNE
62 words
1 min read
Reading compass
Now · PCA (Principal Component Analysis)
PCA and t-SNE
PCA (Principal Component Analysis)
pythonfrom sklearn.decomposition import PCA import matplotlib.pyplot as plt pca = PCA(n_components=2) X_pca = pca.fit_transform(X) plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, cmap='viridis') plt.xlabel(f"PC1 ({pca.explained_variance_ratio_[0]:.1%})") plt.ylabel(f"PC2 ({pca.explained_variance_ratio_[1]:.1%})") plt.title("PCA of Dataset") plt.show()
t-SNE
pythonfrom sklearn.manifold import TSNE tsne = TSNE(n_components=2, random_state=42) X_tsne = tsne.fit_transform(X)
| Method | Linear? | Preserves Distances? | Best For |
|---|---|---|---|
| PCA | Yes | Global | Feature extraction |
| t-SNE | No | Local | Visualization |
| UMAP | No | Both | General |