PCA (Principal Component Analysis) › Concept

Michael BrenndoerferJuly 21, 20253 min read
Machine Learning from ScratchAll chapters
Part 6 of 9Explainability
Chapter 48PCA (Principal Component Analysis) › Concept
Reading section 2 of 9 · Concept · 3 minSection 2 of 9 · 3 min

Book contents

Section 2 of 9 · 3 min read

PCA (Principal Component Analysis) › ConceptOne section · Sections in this chapter2 / 9 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Principal Component Analysis (PCA) is a dimensionality reduction technique that maps high-dimensional data into a lower-dimensional space while preserving as much of the original information as possible. The core idea is straightforward: find the directions where your data varies the most. Think of it like finding the best camera angles to photograph a sculpture. Some angles capture more information about the shape than others. PCA identifies these "best angles" mathematically and lets you represent your data using just the most informative views.

What makes PCA different from simply picking a few features to keep? Instead of choosing existing features, PCA creates entirely new features by combining the original ones. Each new feature, called a principal component, is a weighted sum of all the original features. The first principal component points in the direction of maximum variance. The second principal component points in the direction of maximum remaining variance while being perpendicular to the first. This pattern continues for all components.

PCA is unsupervised, meaning it doesn't need any labels or target variables. It looks purely at the structure of the input data itself. This makes it versatile for many tasks, from visualization to preprocessing to compression.

The method works best when your features are correlated, when they have linear relationships. If age and income both increase together in your data, PCA can capture this pattern in a single component rather than keeping both features separate. By finding these underlying patterns, PCA often reduces dimensionality dramatically while retaining most of the important information. This leads to faster computations, lower storage needs, and sometimes better model performance by filtering out noise.

Advantages

PCA has several strengths that explain its popularity:

Mathematical soundness: PCA has a clear objective (maximize variance) and a closed-form solution through eigenvalue decomposition. There's no iterative optimization that might fail to converge, and no hyperparameters to tune for the core algorithm.

Computational efficiency: For moderate-sized datasets, PCA runs quickly. The eigenvalue decomposition required to find components is well-studied, and modern linear algebra libraries make it efficient. For large datasets, approximation methods like randomized SVD maintain good performance.

Interpretability: Each principal component is a linear combination of the original features. We can examine the coefficients (loadings) to understand which original features contribute most to each component. This makes PCA valuable for both preprocessing and understanding data structure.

Disadvantages

PCA has limitations that practitioners should understand:

Linear assumptions: PCA only captures linear relationships between variables. If your data has non-linear patterns or complex interactions, PCA may miss important structure. For such cases, consider non-linear alternatives like kernel PCA or manifold learning methods.

Scale sensitivity: PCA is sensitive to the scale of input variables. Variables with larger numerical ranges will dominate the principal components, potentially masking patterns in smaller-scale variables. Standardization (mean centering and scaling to unit variance) is typically required before applying PCA, though this preprocessing can alter the interpretation of results.

Variance as importance: PCA assumes that directions of maximum variance are most important. While this often holds true, there are cases where maximum variance directions may not be most relevant for the task. In supervised learning, for example, directions that best separate classes might not align with maximum variance directions.