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
from sklearn.decomposition import PCApca = PCA(n_components=2) # or a fraction: PCA(0.95) keeps 95% of varianceX_reduced = pca.fit_transform(X_scaled)pca.explained_variance_ratio_ # how much variance each component captures
When to use it
Key takeaways
- 01PCA compresses many correlated features into a few uncorrelated components capturing most variance.
- 02Use it for visualisation (2-D), speed, and removing multicollinearity.
- 03explained_variance_ratio_ shows how much information each component keeps.
- 04Scale features first; the trade-off is reduced interpretability of components.
