# Principal Component Analysis

> Projecting data onto the directions of greatest variance for compression, denoising, visualization and faster models. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/pca
Last updated: 2026-11-28

Projecting data onto the directions of greatest variance for compression, denoising, visualization and faster models.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [Linear Algebra for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-algebra), [Encoding Categories and Scaling Numbers](https://www.internhack.in/roadmaps/tracks/machine-learning/encoding-and-scaling)

PCA finds orthogonal directions (principal components) that capture the most variance, then lets you keep only the first few. It is linear algebra in action: eigenvectors of the covariance matrix, computed in practice with SVD.

### Uses

- **Visualization**: plot the first two components to see structure.
- **Compression and speed**: fewer features for downstream models.
- **Denoising**: discard low-variance components that are mostly noise.
- **Decorrelation** of features before linear models.

### How to apply

- **Standardize features first** unless they share units; otherwise the largest-scale feature dominates.
- Choose the number of components from the **explained variance ratio** (for example keep 95%).
- Fit PCA on training data only, inside a pipeline.

### Limitations

Components are linear combinations and can be hard to interpret. PCA captures variance, which is not necessarily what predicts your target. Nonlinear structure needs other tools (kernel PCA, t-SNE, UMAP, autoencoders).

**Good enough to move on** when you can implement PCA from SVD in NumPy, match scikit-learn's result, and choose components from a cumulative variance plot.

## Key concepts

- **Variance and covariance**
- **PCA via SVD**
- **Explained variance ratio**
- **PCA in pipelines**
- **Kernel and incremental PCA**

## Mini project

Apply PCA to the Olivetti faces or MNIST digits, visualize the top components as images, and plot classifier accuracy against the number of components kept.

## Check yourself

Why can PCA throw away a low-variance feature that is actually the most predictive of the target?

## Free resources

- [scikit-learn: Decomposing signals in components](https://scikit-learn.org/stable/modules/decomposition.html) (scikit-learn)
- [Mathematics for Machine Learning (dimensionality reduction chapter)](https://mml-book.github.io/) (MML)

Previous: [Hierarchical and Density-Based Clustering](https://www.internhack.in/roadmaps/tracks/machine-learning/hierarchical-and-density-clustering) · Next: [t-SNE and UMAP for Visualization](https://www.internhack.in/roadmaps/tracks/machine-learning/tsne-umap)

## More in Finding Structure Without Labels

- [k-Means Clustering](https://www.internhack.in/roadmaps/tracks/machine-learning/k-means)
- [Hierarchical and Density-Based Clustering](https://www.internhack.in/roadmaps/tracks/machine-learning/hierarchical-and-density-clustering)
- [Principal Component Analysis](https://www.internhack.in/roadmaps/tracks/machine-learning/pca)
- [t-SNE and UMAP for Visualization](https://www.internhack.in/roadmaps/tracks/machine-learning/tsne-umap)
- [Anomaly and Outlier Detection](https://www.internhack.in/roadmaps/tracks/machine-learning/anomaly-detection)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
