Lecture 15 - PCA and ICA | Stanford CS229: Machine Learning Andrew Ng - Autumn 2018

| Podcasts | February 26, 2026 | 5.23 Thousand views | 1:18:35

TL;DR

Andrew Ng explains Principal Component Analysis (PCA) as a classic non-probabilistic algorithm for linear dimensionality reduction that identifies principal axes of variation through eigenvector decomposition of the covariance matrix, while cautioning that practitioners often apply it unnecessarily.

🎯 Core Concept & Intuition 3 insights

Non-probabilistic dimensionality reduction

Unlike Factor Analysis which models P(X), PCA does not build a density model but instead finds the low-dimensional subspace where data varies most significantly.

Principal axis captures true variation

PCA identifies the direction of maximum variance, such as the underlying height factor when measuring children in both inches and centimeters, effectively separating signal from orthogonal noise.

Two equivalent mathematical formulations

The algorithm equivalently minimizes the sum of squared projection distances to the axis or maximizes the variance of the projected data, with both approaches yielding the same solution via the Pythagorean theorem.

📐 Mathematical Foundation 3 insights

Eigenvectors of covariance matrix

The optimal projection direction u is the principal eigenvector of the covariance matrix Σ, where Σ = (1/m) Σ x_i x_i^T for mean-zero data.

Constrained optimization solution

Maximizing u^T Σ u subject to the constraint ||u|| = 1 yields Σu = λu, proving u must be an eigenvector of Σ with the largest eigenvalue indicating the principal component.

Extension to k dimensions

To reduce from n dimensions to k dimensions, select the top k eigenvectors of Σ corresponding to the k largest eigenvalues, creating a new k-dimensional representation y_i = [u_1^T x_i, ..., u_k^T x_i].

⚙️ Implementation & Reconstruction 2 insights

Mandatory preprocessing requirements

Data must be standardized to zero mean and unit variance before applying PCA to ensure the algorithm captures correlations rather than being dominated by features with larger scales.

Lossy compression and reconstruction

The original high-dimensional data can be approximately reconstructed from the reduced representation using x_i ≈ Σ_{j=1}^k y_{ij} u_j, projecting back onto the principal component subspace.

⚠️ Practical Usage Guidelines 2 insights

Appropriate scale for dimensionality reduction

PCA is designed for high-dimensional data reduction such as 10,000 dimensions to 100 dimensions, not trivial reductions from 2D to 1D as commonly illustrated in tutorials.

Warning against routine application

Ng explicitly cautions that PCA is frequently misapplied when practitioners should work with original features instead, emphasizing that it should only be used when dimensionality reduction specifically serves the downstream task.

Bottom Line

Always standardize your data to zero mean and unit variance before applying PCA, and only use it when you specifically need to reduce dimensionality for computational efficiency or denoising, not as a default preprocessing step for every dataset.

More from Stanford Online

View all
Stanford CS221 | Autumn 2025 | Lecture 20: Fireside Chat, Conclusion
58:49
Stanford Online Stanford Online

Stanford CS221 | Autumn 2025 | Lecture 20: Fireside Chat, Conclusion

Percy Liang reflects on AI's transformation from academic curiosity to global infrastructure, debunking sci-fi misconceptions about capabilities while arguing that academia's role in long-term research and critical evaluation remains essential as the job market shifts away from traditional entry-level software engineering.

16 days ago · 7 points
Stanford CS221 | Autumn 2025 | Lecture 19: AI Supply Chains
1:14:36
Stanford Online Stanford Online

Stanford CS221 | Autumn 2025 | Lecture 19: AI Supply Chains

This lecture examines AI's economic impact through the lens of supply chains and organizational strategy, demonstrating why understanding compute monopolies, labor market shifts, and corporate decision-making is as critical as tracking algorithmic capabilities.

16 days ago · 7 points
Stanford CS221 | Autumn 2025 | Lecture 18: AI & Society
1:12:10
Stanford Online Stanford Online

Stanford CS221 | Autumn 2025 | Lecture 18: AI & Society

This lecture argues that AI developers bear unique ethical responsibility for societal outcomes, framing AI as a dual-use technology that requires active steering toward beneficial applications while preventing misuse and accidental harms through rigorous auditing and an ecosystem-aware approach.

16 days ago · 8 points
Stanford CS221 | Autumn 2025 | Lecture 17: Language Models
1:19:46
Stanford Online Stanford Online

Stanford CS221 | Autumn 2025 | Lecture 17: Language Models

This lecture introduces modern language models as industrial-scale systems requiring millions of dollars and trillions of tokens to train, explaining their fundamental operation as auto-regressive next-token predictors that encode language structure through massive statistical modeling.

16 days ago · 10 points