Data Science ยท Chapter 34 of 43
Dimensionality Reduction (PCA)
PCA projects data onto the directions of GREATEST VARIANCE, reducing features while keeping most of the information.
Great for visualisation, speeding up training and denoising.
Example 1 (python)
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
X2 = pca.fit_transform(X)
print(pca.explained_variance_ratio_)Output
[0.72 0.18]First two components explain 90% variance.
Example 2 (python)
# Always scale features before PCAPCA is variance-based โ scale matters.
Key points
- Reduces feature dimensionality.
- Keeps most variance.
- Ideal for 2D/3D visualisation.
- Scale before PCA.
๐ก Note: PCA components are hard to interpret directly โ they mix many original features.
