BRAGA

02 Writing02-02 Notes02-02-433

Projection (Encoding)

Published 16 Apr 202612 min read
Contents
  1. 01Deep Breakdown
  2. 02Why this matters in PCA
  3. 03What the eigenvalue means
  4. 04Geometric meaning
  5. 05Orthogonality Because the covariance matrix SS is symmetric
  6. 06Connection to projection
  7. 07DA/DS relevance
  8. 08Flowchart
  9. 09Real-world use
  10. 10The formula, piece by piece
  11. 11The formula in words
  12. 12Critical Concepts
  13. 13Step-by-step calculation (tiny example)
  14. 14Code examples
  15. 15Self-check: mathematical verification
  16. 16Common Pitfalls and Edge Cases
  17. 17References and Standard Results
Sv=λvSv=\lambda v
(1)

We are working on the eigenvector equation for Principal Component Analysis, PCA, defined by

Sv=λv,Sv=\lambda v,
(2)

where SS is the sample covariance matrix, vv is an eigenvector, and λ\lambda is the corresponding eigenvalue. In PCA, the eigenvectors of SS are the principal directions, or principal axes, and the eigenvalues give the variance explained along those directions. This is the central linear-algebra equation behind PCA, covariance-based dimensionality reduction, and many factor-style analyses.

Deep Breakdown

The eigenvector equation is the mathematical heart of PCA. After we center the data and compute the sample covariance matrix, PCA asks a very specific question: > In which direction does the data vary the most? That direction is the first principal component. Then PCA asks: > What is the next direction of greatest variance, subject to being orthogonal to the first? That becomes the second principal component, and so on. The answer to these questions comes from the eigenvector equation:

Sv=λvSv=\lambda v
(3)

where:

  • SS is the sample covariance matrix,
  • vv is a direction vector,
  • λ\lambda is a scalar.

This equation says that when the covariance matrix acts on the vector vv, the result points in exactly the same direction as vv, only rescaled by λ\lambda. That is what makes vv an eigenvector.

Why this matters in PCA

The covariance matrix describes how the centered features vary together. If we take a unit direction vector vv and project the data onto that direction, the variance of the projected data is:

v⊤Svv^\top S v
(4)

PCA chooses the direction vv that maximizes this variance, under the constraint that:

∥v∥2=1\|v\|_2=1
(5)

The optimization solution leads directly to:

Sv=λvSv=\lambda v
(6)

So PCA is not using eigenvectors by accident. The eigenvectors are exactly the solutions to the variance-maximization problem.

What the eigenvalue means

Each eigenvector has a corresponding eigenvalue:

Sv=λvSv=\lambda v
(7)

The eigenvalue λ\lambda tells us how much variance exists in that principal direction.

So:

  • larger λ\lambda means more variance explained,
  • smaller λ\lambda means less variance explained.

This is why PCA orders components by decreasing eigenvalue.

If:

λ1≥λ2≥⋯≥λp\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_p
(8)

then:

  • v1v_1 is the first principal axis,
  • v2v_2 is the second principal axis,
  • and so on.

Geometric meaning

The covariance matrix stretches space differently in different directions. Eigenvectors identify the special directions that do not rotate under this covariance transformation. They only get scaled. In a PCA plot, these directions are the main axes of the data cloud. That is why people call them principal axes.

Orthogonality Because the covariance matrix SS is symmetric

S⊤=SS^\top=S
(9)

its eigenvectors can be chosen to be orthogonal. That is perfect for PCA, because the principal components are supposed to represent independent directions of variation in Euclidean geometric terms.

So the PCA directions are:

  • orthogonal,
  • ordered by variance,
  • extracted from the covariance matrix.

Connection to projection

If we project the centered data onto the first eigenvector v1v_1, we get the first principal component scores. If the centered data matrix is XcX_c, then the score vector is:

Xcv1X_c v_1
(10)

That is the data expressed along the first principal axis. So the eigenvector equation gives the directions, and projection onto those directions gives the transformed lower-dimensional coordinates.

DA/DS relevance

In DA/DS work, this matters because PCA is widely used for:

  • dimensionality reduction,
  • visualization,
  • denoising,
  • collinearity compression,
  • feature extraction,
  • preprocessing before modeling.

Understanding the eigenvector equation makes PCA much less mysterious. It shows that PCA is really a structured search for directions of maximal variance inside the covariance geometry of the data.

Flowchart

Start withcentered datamatrix X_cComputesamplecovariancematrix SSolveeigenvectorequation S v =lambda vObtaineigenvectorsv_1, v_2, ..., v_pObtaineigenvalueslambda_1,lambda_2, ...,lambda_pInterpreteigenvectors asprincipaldirectionsInterpreteigenvalues asexplainedvariancesProject dataonto leadingeigenvectorsObtainlower-dimensional PCArepresentation

Real-world use

Where it is used

The eigenvector equation is used whenever PCA is performed from the covariance matrix, including dimensionality reduction, exploratory data analysis, feature compression, and factor-style interpretation.

Problem it solves

It solves the problem of identifying the directions in feature space along which the data vary the most. Without this, dimensionality reduction would have no principled way to choose which directions to keep.

How it solves the problem

It finds the eigenvectors of the sample covariance matrix. These eigenvectors are the principal axes, and their eigenvalues quantify the variance along each axis. The analyst then keeps the leading directions with the largest eigenvalues.

Example in a business

Suppose a business analyst has many customer variables such as spend, purchase frequency, average basket size, return rate, and discount sensitivity. These variables are correlated. PCA solves the eigenvector equation of their covariance matrix and identifies a few dominant latent directions, such as “overall value” or “promotion sensitivity,” which can then be used in segmentation or dashboard simplification.

The formula, piece by piece

Symbol Meaning
SS Sample covariance matrix
vv Eigenvector of SS, also a principal direction in PCA
λ\lambda Eigenvalue associated with vv
vkv_k kk-th eigenvector
λk\lambda_k kk-th eigenvalue
XcX_c Centered data matrix
XcvkX_c v_k Projection of centered data onto principal direction vkv_k

Canonical eigenvector equation:

Sv=λvSv=\lambda v
(11)

Ordered eigenvalue convention in PCA:

λ1≥λ2≥⋯≥λp≥0\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_p \ge 0
(12)

Variance of projection onto direction vv:

Var(Xcv)=v⊤Sv\mathrm{Var}(X_c v)=v^\top S v
(13)

Unit-norm constraint for PCA direction:

∥v∥2=1\|v\|_2=1
(14)

Principal component score vector for direction vkv_k:

zk=Xcvkz_k=X_c v_k
(15)

Explained variance ratio for component kk:

λk∑j=1pλj\frac{\lambda_k}{\sum_{j=1}^{p}\lambda_j}
(16)

The formula in words

Take the covariance matrix SS and a direction vector vv. If multiplying SS by vv gives back the same direction scaled by some number λ\lambda, then vv is an eigenvector and λ\lambda is its eigenvalue.

In PCA, that means:

  • vv is a principal axis,
  • λ\lambda is the variance along that axis.

So the eigenvector equation identifies both the important directions and how important they are.

Critical Concepts

  • Eigenvectors of the covariance matrix are principal directions. This is the core PCA fact.
  • Eigenvalues measure explained variance. Bigger eigenvalues mean more important components.
  • PCA orders components by decreasing eigenvalue. The first principal component explains the most variance.
  • Covariance symmetry matters. Because SS is symmetric, PCA directions can be chosen orthogonal.
  • Projection comes after direction selection. Solve for vkv_k, then compute scores as XcvkX_c v_k.
  • PCA is a variance-maximization method. The eigenvector equation is the solution to that constrained optimization problem.
  • Centered data are required. Without centering, the covariance-based interpretation breaks.

Step-by-step calculation (tiny example)

Suppose the sample covariance matrix is:

S=[2001]S= \begin{bmatrix} 2 & 0\\ 0 & 1 \end{bmatrix}
(17)

We want to solve:

Sv=λvSv=\lambda v
(18)

Let:

v=[v1v2]v= \begin{bmatrix} v_1\\ v_2 \end{bmatrix}
(19)

Step 1, write the matrix equation

[2001][v1v2]=λ[v1v2]\begin{bmatrix} 2 & 0\\ 0 & 1 \end{bmatrix} \begin{bmatrix} v_1\\ v_2 \end{bmatrix} = \lambda \begin{bmatrix} v_1\\ v_2 \end{bmatrix}
(20)

This gives:

[2v1v2]=[λv1λv2]\begin{bmatrix} 2v_1\\ v_2 \end{bmatrix} = \begin{bmatrix} \lambda v_1\\ \lambda v_2 \end{bmatrix}
(21)

So the coordinate equations are:

2v1=λv12v_1=\lambda v_1
(22)
v2=λv2v_2=\lambda v_2
(23)

Step 2, find one eigenvalue and eigenvector Take

λ=2\lambda=2
(24)

Then the equations become:

2v1=2v12v_1=2v_1
(25)
v2=2v2⇒v2=0v_2=2v_2 \Rightarrow v_2=0
(26)

So one eigenvector is:

v1=[10]v_1= \begin{bmatrix} 1\\ 0 \end{bmatrix}
(27)

Step 3, find the second eigenvalue and eigenvector Take

λ=1\lambda=1
(28)

Then:

2v1=v1⇒v1=02v_1=v_1 \Rightarrow v_1=0
(29)
v2=v2v_2=v_2
(30)

So another eigenvector is:

v2=[01]v_2= \begin{bmatrix} 0\\ 1 \end{bmatrix}
(31)

Step 4, interpret The first principal axis is

[10]\begin{bmatrix} 1\\ 0 \end{bmatrix}
(32)

with variance:

λ1=2\lambda_1=2
(33)

The second principal axis is:

[01]\begin{bmatrix} 0\\ 1 \end{bmatrix}
(34)

with variance:

λ2=1\lambda_2=1
(35)

Tiny plain-language reading

The data vary twice as much in the first coordinate direction as in the second, so the first axis becomes the first principal component direction.

Code examples

Beginner friendly Example [Python])

markdown
import numpy as np # Eigenvectors and eigenvalues of a covariance matrix
S = np.array([ [2, 0], [0, 1]
], dtype=float) eigenvalues, eigenvectors = np.linalg.eigh(S) # sort from largest to smallest
order = np.argsort(eigenvalues)[::-1]
eigenvalues = eigenvalues[order]
eigenvectors = eigenvectors[:, order] print("Eigenvalues:")
print(eigenvalues)
print("Eigenvectors:")
print(eigenvectors)

Explanation :

  • np.linalg.eigh is used because the covariance matrix is symmetric.
  • The eigenvectors are the principal directions.
  • The eigenvalues tell how much variance each direction explains.

Beginner friendly Example [R])

r
# Eigenvectors and eigenvalues of a covariance matrix
S <- matrix( c( 2, 0, 0, 1 ), nrow = 2, byrow = TRUE
) eigen_result <- eigen(S) cat("Eigenvalues:\n")
print(eigen_result$values)
cat("Eigenvectors:\n")
print(eigen_result$vectors)

Explanation :

  • eigen(S) computes eigenvalues and eigenvectors.
  • For PCA, the leading eigenvector is the first principal axis.

Final Professional Example [Python])

markdown
from __future__ import annotations from dataclasses import dataclass
from typing import Sequence import numpy as np RANDOM_SEED = 42 @dataclass(frozen=True)
class PcaCovarianceExample: data_matrix: Sequence[Sequence[float]] feature_names: Sequence[str] def validate(self) -> None: if len(self.data_matrix) < 2: raise ValueError("At least two observations are required.") if len(self.feature_names) == 0: raise ValueError("At least one feature name is required.") feature_count = len(self.feature_names) for row in self.data_matrix: if len(row) != feature_count: raise ValueError("Each row must match the number of feature names.") def center_columns(X: np.ndarray) -> np.ndarray: return X - np.mean(X, axis=0) def sample_covariance_matrix(X_centered: np.ndarray) -> np.ndarray: observation_count = X_centered.shape[0] return (X_centered.T @ X_centered) / (observation_count - 1) def summarize_pca_directions(example: PcaCovarianceExample) -> None: example.validate() X = np.array(example.data_matrix, dtype=float) X_centered = center_columns(X) S = sample_covariance_matrix(X_centered) eigenvalues, eigenvectors = np.linalg.eigh(S) order = np.argsort(eigenvalues)[::-1] eigenvalues = eigenvalues[order] eigenvectors = eigenvectors[:, order] explained_variance_ratio = eigenvalues / np.sum(eigenvalues) print("PCA eigenvector-equation summary") print("-" * 72) print("Feature names:") print(list(example.feature_names)) print("-" * 72) print("Sample covariance matrix S:") print(S) print("-" * 72) print("Eigenvalues:") print(eigenvalues) print("Explained variance ratios:") print(explained_variance_ratio) print("-" * 72) print("Eigenvectors, principal axes:") print(eigenvectors) print("-" * 72) print("First principal component scores:") print(X_centered @ eigenvectors[:, 0]) def main() -> None: example = PcaCovarianceExample( feature_names=["annual_spend", "purchase_frequency", "basket_size"], data_matrix=[ [1200.0, 12.0, 100.0], [1500.0, 15.0, 110.0], [1800.0, 18.0, 130.0], [1600.0, 14.0, 115.0], ], ) summarize_pca_directions(example) if __name__ == "__main__": main()

What this professional example teaches:

  1. PCA starts from the covariance matrix of centered data.
  2. Solving the eigenvector equation gives principal directions and explained variances.
  3. Ordering eigenvalues from largest to smallest defines the PCA ranking.

Projecting centered data onto leading eigenvectors gives principal component scores.

Self-check: mathematical verification

Re-derivation from the variance-maximization problem PCA chooses a unit direction vector vv that maximizes projected variance

max⁡v v⊤Svsubject tov⊤v=1\max_v \ v^\top S v \quad \text{subject to} \quad v^\top v = 1
(36)

Use a Lagrange multiplier λ\lambda:

L(v,λ)=v⊤Sv−λ(v⊤v−1)\mathcal{L}(v,\lambda)=v^\top S v - \lambda(v^\top v - 1)
(37)

Differentiate with respect to vv:

∇vL=2Sv−2λv\nabla_v \mathcal{L}=2Sv-2\lambda v
(38)

Set the gradient equal to zero:

2Sv−2λv=02Sv-2\lambda v=0
(39)

Divide by 2:

Sv=λvSv=\lambda v
(40)

This matches the canonical eigenvector equation exactly.

Eigenvalue-as-variance check If vv is a unit eigenvector satisfying

Sv=λvSv=\lambda v
(41)

then projected variance is:

v⊤Svv^\top S v
(42)

Substitute the eigenvector equation:

v⊤Sv=v⊤(λv)=λv⊤vv^\top S v = v^\top (\lambda v)=\lambda v^\top v
(43)

Because ∣v∣2=1|v|_2=1, we have:

v⊤v=1v^\top v = 1
(44)

So:

v⊤Sv=λv^\top S v=\lambda
(45)

This confirms that the eigenvalue equals the variance along that principal direction.

Orthogonality check The sample covariance matrix SS is symmetric

S⊤=SS^\top=S
(46)

For symmetric matrices, eigenvectors corresponding to distinct eigenvalues are orthogonal. That matches the PCA requirement that principal axes be orthogonal.

Non-negativity check

A sample covariance matrix is positive semidefinite, so for any vector aa:

a⊤Sa≥0a^\top S a \ge 0
(47)

Since eigenvalues are projected variances, they must satisfy:

λk≥0\lambda_k \ge 0
(48)

This confirms the nonnegative variance interpretation.

Projection-score check Once a principal axis vkv_k is found, projecting centered data onto it gives

zk=Xcvkz_k=X_c v_k
(49)

This is dimensionally and geometrically correct, because it produces the coordinate of each observation along that axis.

Verbal-to-algebra consistency

The verbal explanation says eigenvectors are the principal directions and eigenvalues are the variance along those directions. The derivation confirms both claims exactly.

Structural verification

  • Opening restatement paragraph is present.
  • All required sections are present and non-empty.
  • Block equations use `
......
(50)

`.

  • Symbol-table entries use math mode such as $S$, $v$, $\lambda$, $X_c$, and $z_k$.
  • Mermaid uses flowchart TD and node text in ["..."].
  • Three code blocks are present: Python beginner, R beginner, Python professional.
  • Links to sample covariance, projection, PCA, and factor analysis are explicitly included.
  • No placeholder text remains.

Common Pitfalls and Edge Cases

  • Skipping centering before PCA: Without centered data, the covariance interpretation of principal directions becomes distorted.
  • Confusing eigenvectors with projected scores: Eigenvectors are directions; scores are data coordinates after projection.
  • Ignoring eigenvalue ordering: PCA requires ordering from largest variance to smallest.
  • Forgetting the unit-norm convention: Eigenvectors are usually normalized for consistent interpretation.
  • Mixing covariance PCA with correlation PCA: The choice matters when features are on very different scales.
  • Assuming all eigenvalues will be strictly positive: Some can be zero if the data are rank-deficient.
  • Treating PCA directions as causal factors: They are variance directions, not causal explanations.
  • Ignoring sign indeterminacy: If vv is an eigenvector, then −v-v is also an eigenvector of the same component.

References and Standard Results

  • Eigenvector equation, Sv=λvSv=\lambda v
  • Variance-maximization characterization of PCA
  • Sample covariance matrix as the PCA input
  • Eigenvalues as explained variances
  • Eigenvectors as principal axes
  • Orthogonality of eigenvectors for symmetric covariance matrices
  • Score projection formula, zk=Xcvkz_k=X_c v_k
  • Explained variance ratio, λk/∑jλj\lambda_k / \sum_j \lambda_j

#machine-learning#machine-learning-algorithms#dimensionality-reduction-principal-component-analysis-pca

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close