Machine Learning Β· Chapter 19 of 40
PCA (Dimensionality Reduction)
PCA projects data onto the directions of greatest VARIANCE. Reduces feature count while preserving as much information as possible.
Useful 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 2 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.
- Great for visualisation (2 or 3 comps).
- Scale features first.
π‘ Note: PCA components are hard to interpret β they are linear combinations of many original features.
