Lecture 15 - PCA and ICA | Stanford CS229: Machine Learning Andrew Ng - Autumn 2018
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 MS&E435 Economics of the AI Supercycle | Spring 2026 | Applications, Coding AI
Vercel founder Guillermo Rauch explains how AI coding agents have expanded the software development market by 10-100x, driving a fundamental shift from traditional web services to 'agentic infrastructure' where tokens replace pixels as the primary commodity and deployment becomes the critical value creator.
Stanford MS&E435 Economics of the AI Supercycle | Spring 2026 | Building AI Factories
Crusoe Energy CEO Chase Lockmiller explains how AI data centers represent history's second-largest infrastructure investment, driven by the economic potential of scalable 'digital labor.' He reveals Crusoe's strategy of building massive AI factories in stranded-power locations like Abilene, Texas, to overcome the industry's critical bottleneck: energized data center capacity.
AI in Healthcare Series: Inside the Rise of AI in Healthcare, Open Evidence and Cyber Risks
Former U.S. Chief Data Scientist DJ Patil warns that healthcare systems are dangerously unprepared for AI-enabled cyberattacks from nation states, while simultaneously seeing rapid democratization of medical knowledge through tools like Open Evidence that are fundamentally reshaping the doctor-patient relationship.
Stanford CS153 Frontier Systems | Scale, AGI, and the Future of Everything
Sam Altman explains how AI has fundamentally altered startup economics, enabling small teams to achieve unprecedented scale, while sharing OpenAI's journey from research lab to product company and arguing that pushing systems beyond conventional scaling limits often reveals emergent properties that consensus thinking misses.