Lesson 13 of 15
Principal Component Analysis
Principal Component Analysis (PCA)
PCA finds the directions of maximum variance in data — the principal components. The first PC is the direction along which the data varies most.
Algorithm
- Centre the data by subtracting the mean
- Compute the covariance matrix
- Find the dominant eigenvector of via power iteration
The dominant eigenvector is the first principal component.
Example
Data: — perfectly collinear along
After centring, the covariance matrix is:
The first PC (dominant eigenvector) points along :
Your Task
Implement pca_first_component(data) that returns the first principal component (unit vector) of a list of 2D points.
Python runtime loading...
Loading...
Click "Run" to execute your code.