Lecture 15: PCA and ICA
Stanford CS229 lecture 15 notes: PCA and ICA.
- cs229
- machine-learning
- course-notes
On this page
Principal Component Analysis (PCA)#
Problem: your data has dimensions, but a lot of them are redundant. Maybe two features are almost the same thing (a length in cm and in inches, with some noise). We want to find the main directions along which the data actually varies, and project onto them.
Preprocessing#
- Subtract the mean of each feature, so the data is centered at the origin.
- (Optional) Divide each feature by its standard deviation, so all features are on the same scale. This matters if the features have wildly different units.
The idea#
Find the unit vector such that when you project the data onto , the variance of the projections is maximized.
The projection of onto has length , so we maximize:
where is the empirical covariance matrix.
The answer: is the top eigenvector of . Likewise, the top eigenvectors are the best directions.
The algorithm#
- Compute the covariance matrix .
- Find its top eigenvectors .
- Represent each point by its coordinates in this new basis:
Before: After projecting on u1:
. . / . . . . . . . . .
. . . / . (all the info in
. . ./ . 1 dimension)
. /.
/How many components?#
Look at the eigenvalues. Each eigenvalue is the variance captured by that direction. Pick so that you keep, say, 95 or 99% of the total variance.
Uses#
- Compression and speeding up other algorithms
- Visualization (reduce to 2D or 3D)
- Noise reduction
- Removing correlated features, which can also help a learning algorithm that's overfitting
Independent Component Analysis (ICA)#
PCA finds directions of maximum variance, which are orthogonal. ICA has a different goal: find directions along which the data is independent.
The cocktail party problem#
There are speakers, and microphones. Each microphone records a mix of all the speakers. The sources are (unknown) and what we observe is:
where is an unknown mixing matrix. Our goal is to find the unmixing matrix so that we can recover .
Why is this possible?#
Because we assume the sources are independent of each other and non-Gaussian. (The speakers are talking independently.)
Why non-Gaussian? Because a Gaussian is rotationally symmetric. If the sources were Gaussian, then any rotation of them would look statistically identical, and there'd be no way to tell the right from a rotated one. The non-Gaussianity breaks this symmetry.
The algorithm#
Assume each source has a density (for example, a sigmoid-based CDF , whose derivative is the density). Because the sources are independent, , and with :
We maximize the log likelihood using stochastic gradient ascent:
After it converges, recover the sources with .
Ambiguities#
ICA can't recover everything:
- The ordering of the sources (which output is speaker 1?)
- The scale and sign (a source's volume and polarity are unknown)
For audio, these don't matter at all.