MACHINE LEARNING / 8. PCA & DIMENSIONALITY REDUCTION
PCA & Dimensionality Reduction
Compressing data while preserving variance
EXPLANATION
High-dimensional data has the "curse of dimensionality" — distances become meaningless, models overfit, visualization is impossible. Dimensionality reduction fixes this. PCA (Principal Component Analysis): • Finds orthogonal directions (principal components) of maximum variance • Projects data onto top-K components • Linear transformation — new features are combinations of original features • Unsupervised — doesn't use labels Algorithm: 1. Center the data (subtract mean) 2. Compute covariance matrix 3. Compute eigenvectors and eigenvalues 4. Sort by eigenvalue (variance explained) 5. Project onto top-K eigenvectors t-SNE and UMAP: non-linear, used for visualization only (2D/3D). t-SNE preserves local structure, UMAP is faster and preserves more global structure. Rule of thumb: use PCA before training if you have 100+ features, or as preprocessing to remove noise. Use t-SNE/UMAP for visualization.
DATA FLOW
Original data: 100 features
↓
PCA finds directions of maximum variance:
PC1: direction explaining most variance (say 40%)
PC2: orthogonal to PC1, explains next most (25%)
PC3: orthogonal to both, explains next (15%)
...
↓
Keep top K components (explaining 95% variance)
↓
Reduced data: K features (e.g. K=10 instead of 100)
Explained variance ratio:
PC1: ████████████████ 40%
PC2: ██████████ 25%
PC3: ██████ 15%
... sum to 95% → keep theseCODE