Create your own
Lesson illustration

Interpreting Covariance Matrix Eigenvectors and Eigenvalues

Good to see you again. In the previous lesson, gradient descent made the geometry of a loss surface concrete: feature scales influence curvature, and curvature determines how readily one learning rate can make progress. We now use the same linear-algebra vocabulary to describe the geometry of the data itself.

This lesson explains what a covariance matrix says about a multivariate dataset. By the end, you should be able to read its eigenvectors as mutually perpendicular directions of variation and its eigenvalues as the variances along those directions. This is the mathematical core that will later make principal component analysis (PCA) feel like a change of coordinate system rather than a mysterious algorithm.


From raw columns to a geometric object

Suppose each observation has numerical features. Write the centered data matrix as

where each row is an observation after subtracting the feature-wise mean. Centering matters: we want to describe variation around the data cloud's centre, not its location in the original coordinate system.

A sample covariance matrix can be written as

The denominator is sometimes rather than , depending on whether one is treating the data as a sample or an entire population. That choice rescales every eigenvalue slightly but does not change the eigenvector directions.

For two features,

has a straightforward interpretation:

  • and are the variances of the individual features.
  • is their covariance: positive when deviations from their means tend to share a sign, negative when they tend to have opposing signs.
  • The matrix is symmetric, a property that gives it especially useful eigenvalue and eigenvector behavior.

The covariance matrix records second-order geometry: overall spread and linear co-movement. It does not tell us whether the data cloud is Gaussian, multimodal, crescent-shaped, or otherwise structured in more complicated ways. Distinct distributions can share the same covariance matrix.

Visual Explanation of Principal Component Analysis, Covariance, SVD

Watch “Visual Explanation of Principal Component Analysis, Covariance, SVD” by Em Freedman for a compact visual introduction to covariance and the role of eigendirections.

Watch the core roles to establish the direction-versus-magnitude distinction. Then watch covariance matrix, focusing on why variances occupy the diagonal and covariances the off-diagonal entries. Finally, skip to principal axes for the visual account of why the new axes are perpendicular and aligned with the data spread.


Variation along an arbitrary direction

The original feature axes are not necessarily meaningful directions for describing variation. If customer activity and spend both tend to rise together, for example, the cloud may be elongated diagonally rather than horizontally or vertically. We need a way to ask: how variable are the data when viewed along a chosen direction?

Let be a unit vector, so that

Projecting centered observation onto this direction gives the scalar coordinate

The variance of all projected coordinates is

This quadratic expression is called a Rayleigh quotient when is constrained to have unit length. It is the precise mathematical version of rotating an axis through a data cloud and measuring how widely the projections spread along it.

We want the direction that maximizes this quantity:

The length constraint is essential. Without it, multiplying any candidate direction by would multiply the apparent variance by , which tells us nothing about orientation.

Using a Lagrange multiplier , define

Differentiating with respect to and setting the derivative to zero gives

or equivalently,

This is the eigenvalue equation. It appears not because eigenvectors are an arbitrary linear-algebra trick, but because they solve the meaningful optimization problem: find a direction along which the centered observations have greatest variance.


The central interpretation

For a covariance matrix:

Order the eigenvalues from largest to smallest:

Their corresponding unit eigenvectors are

Then:

  1. is the direction along which the data vary most.
  2. is the direction of greatest remaining variation subject to being perpendicular to .
  3. The later eigenvectors describe progressively smaller orthogonal sources of variation.

Because is symmetric, eigenvectors associated with distinct eigenvalues can be chosen to be orthonormal:

This provides a rotated coordinate system in which the coordinates are uncorrelated. The covariance matrix becomes diagonal:

where has the eigenvectors as its columns and

contains the eigenvalues.

[PDF] Lecture Notes on Principal Component Analysis

Read the Stanford lecture notes’ sections “1.4 Covariance matrix” and “1.6 PCA by diagonalizing the covariance matrix.” They connect the entries of a covariance matrix to the orientation of a data cloud, then explain why eigendecomposition finds the natural axes.

In Section 1.4, begin at the directional intuition. Focus on the contrast between positive covariance, negative covariance, and near-zero covariance. Then read all of Section 1.6, beginning the diagonalization argument. The final phrase previews PCA; for this lesson, concentrate on the claim that the eigendirections are directions of maximal and minimal variance.


Reading the shape of a two-feature dataset

A two-dimensional elliptical data cloud. The long black vector marks the eigenvector with the largest eigenvalue, the dominant direction of variation; the shorter perpendicular vector marks the second eigendirection, where variation is smaller.

The image shows the geometric situation to keep in mind. A cloud that is elongated along a diagonal cannot be adequately summarized by saying “both and have high variance.” The key pattern is that they vary together. The first eigendirection captures this joint movement.

Consider the covariance matrix

The equal diagonal entries say that the two original variables have the same individual variance, . The positive off-diagonal covariance says that above-average values of one variable tend to occur with above-average values of the other.

Its eigendecomposition is particularly simple:

Interpret these, rather than treating them as calculation outputs:

QuantityInterpretation
The dominant direction increases both features together, in equal proportion.
The projected data have variance in that joint-increase direction.
The perpendicular direction contrasts the two features: one rises while the other falls.
There is relatively little variation in that contrast.

The total variance is

It also equals the sum of the eigenvalues:

Thus, the first direction accounts for

or of the total variance. Most of the variation can be described as a shared movement of the two variables; the independent contrast is small.

Two details are worth keeping straight:

  • The sign of an eigenvector is arbitrary. Both and describe the same undirected axis. A software library may choose either.
  • The eigenvalue is a variance, so the standard deviation along the direction is . In an ellipse picture, axis lengths are proportional to , not itself.

Useful boundary cases

These cases make covariance eigenstructure easier to diagnose in real outputs.

No covariance

If

the original axes already coincide with the principal directions. The eigenvectors are the standard coordinate vectors:

with eigenvalues and . There is no rotation to discover; the data are simply more variable in the first feature than in the second.

Nearly perfect linear dependence

If two centered features are almost exact linear copies of one another, one eigenvalue is near zero. The data cloud is close to a line rather than filling a two-dimensional area.

A near-zero eigenvalue can therefore mean:

  • strong redundancy among numerical features;
  • a dataset lying close to a lower-dimensional subspace;
  • or, in an engineering setting, possible duplicated, derived, or nearly deterministic columns.

It does not automatically mean that a feature may be discarded safely for a predictive task. A direction with low global variance can still contain signal for a rare but valuable target outcome.

Equal eigenvalues

When eigenvalues are equal, such as

the data have equal variance in every direction. The cloud is circular in two dimensions. No direction is uniquely “first,” and any orthonormal pair can serve as eigenvectors. This is a practical reminder not to overinterpret an eigenvector when its eigenvalue is nearly tied with another.


Why feature scale remains a modelling decision

The covariance matrix retains the units and scales of the original features. If one column is annual revenue in dollars and another is a count of support tickets, raw covariance-based eigenvalues are likely dominated by revenue merely because its numerical scale is larger.

This connects directly to the feature-scaling lesson:

  • Covariance PCA preserves absolute-scale variation. It is reasonable when the units are commensurate and magnitude itself is meaningful.
  • Standardizing each feature to mean and variance before calculating covariance makes the analysis equivalent to using a correlation matrix. It gives each feature equal initial scale.

Neither choice is universally correct. It encodes a product and domain judgment about whether a unit change or a standard-deviation-sized change is the meaningful basis for comparison. In a technical proposal, asking “Was PCA fit on raw features or standardized features, and why?” is usually more informative than merely noting the number of components retained.


A brief numerical verification

In a notebook, np.linalg.eigh is the appropriate NumPy routine for a real symmetric covariance matrix. Unlike the general eig, it is designed for symmetric matrices and returns real eigenvalues with numerically stable orthogonal eigenvectors.

import numpy as np

S = np.array([
    [4.0, 3.0],
    [3.0, 4.0],
])

eigenvalues, eigenvectors = np.linalg.eigh(S)

# eigh returns ascending eigenvalues, so reverse both outputs.
order = np.argsort(eigenvalues)[::-1]
eigenvalues = eigenvalues[order]
eigenvectors = eigenvectors[:, order]

print("eigenvalues:\n", eigenvalues)
print("\neigenvectors as columns:\n", eigenvectors)

# Confirm S u_k = lambda_k u_k
print("\nEigenvalue equation holds:")
print(np.allclose(S @ eigenvectors, eigenvectors * eigenvalues))

# Confirm orthonormality and conservation of total variance.
print("\nU^T U:\n", eigenvectors.T @ eigenvectors)
print("\ntrace(S):", np.trace(S))
print("sum of eigenvalues:", eigenvalues.sum())

When interpreting output, each column of eigenvectors is an eigenvector. Expect signs that may differ from the hand calculation; for example, NumPy could return

rather than its positive version. That is identical geometrically.


Key takeaways

A covariance matrix describes the spread and linear co-movement of centered multivariate data. Its eigendecomposition identifies a coordinate system aligned with the data cloud:

  • Each eigenvector is a direction of variation.
  • The largest-eigenvalue eigenvector is the direction of greatest variance.
  • Each eigenvalue is the variance of the data projected onto its eigenvector.
  • Covariance-matrix eigenvectors can be made perpendicular, so each direction captures variation distinct from the preceding ones.
  • The sum of eigenvalues equals total feature variance:

The geometry also explains why these directions later become principal components: retaining the directions with large eigenvalues preserves the greatest amount of linear variation, while low-eigenvalue directions represent little remaining spread.

This completes the linear algebra and optimization module. Next, the course moves from geometry to uncertainty, beginning with expectations, variances, and covariances as quantities computed from explicit probability models.

Can't find a good explanation? Sign up and we'll make it for you

Sign up