Skip to main content
Albero Academy

Dimensionality Reduction (PCA)

Compress many features into a few, keeping most information.

Model Selection & Unsupervised8 min

PCA (Principal Component Analysis) reduces many correlated features to a few uncorrelated components that capture most of the variance — for visualisation, speed, and fighting the curse of dimensionality.

Applying PCA

reduce dimensions
from sklearn.decomposition import PCA
pca = PCA(n_components=2) # or a fraction: PCA(0.95) keeps 95% of variance
X_reduced = pca.fit_transform(X_scaled)
pca.explained_variance_ratio_ # how much variance each component captures

When to use it

Key takeaways

  1. 01PCA compresses many correlated features into a few uncorrelated components capturing most variance.
  2. 02Use it for visualisation (2-D), speed, and removing multicollinearity.
  3. 03explained_variance_ratio_ shows how much information each component keeps.
  4. 04Scale features first; the trade-off is reduced interpretability of components.

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.