Goal
Understand covariance as geometry: once variables are centered, covariance behaves like an inner product, correlation behaves like cosine, PCA becomes diagonalization, and whitening becomes a rotate-and-rescale change of coordinates.
Motivation
The previous lesson showed that probability can be written in linear-algebra language. This lesson tightens that connection.
Instead of thinking of covariance as just another formula, we will treat it as the structure that gives random variables lengths, angles, and orthogonality. Once that clicks, several later ideas stop feeling unrelated.
Prerequisites
- Lesson 12: Covariance.
- Lesson 13: Probability as Linear Algebra.
Notation / Symbol Table
| Symbol | Plain-English name | Meaning |
|---|---|---|
| or | centered | The mean-zero version of random variable . |
| or | centered | The mean-zero version of random variable . |
| covariance | Inner-product-like pairing of centered random variables. | |
| variance | Covariance of with itself. | |
| correlation | Normalized covariance, analogous to cosine. | |
| covariance matrix | Gram matrix built from pairwise covariances. | |
| eigendecomposition | Rotation into principal directions followed by axis scaling. | |
| whitening scale | Rescales principal directions to unit variance. |
We will use
as the key bridge between probability and geometry.
Core Ideas
Centered random variables behave like vectors
Once we center random variables, we can compare them in a way that ignores their means and focuses only on variation.
That makes the pairing
feel like a dot product:
- it is symmetric;
- it is linear in each slot;
- it is nonnegative when applied to the same variable twice.
So covariance is not only a statistic. It is the geometric structure on this vector space.
Variance is the induced squared norm
If covariance plays the role of inner product, then variance plays the role of squared length:
This is the same relationship as
in ordinary Euclidean space.
Correlation is cosine
Normalize covariance by the lengths of the variables:
That is exactly the same pattern as
So correlation measures angle-like alignment:
- means the variables point in the same centered direction;
- means they point in opposite directions;
- means they are orthogonal in the covariance sense.
The covariance matrix is a Gram matrix
For a random vector with coordinates , the covariance matrix is
That means is the Gram matrix formed by pairing each coordinate with every other coordinate.
This is why it is symmetric and why diagonalization is the right move. We are looking for the basis in which the geometric structure becomes as simple as possible.
PCA is a rotation into the natural basis
Because covariance matrices are symmetric, they admit an orthogonal eigendecomposition:
The columns of are orthogonal principal directions. In that basis, the covariance matrix is diagonal:
PCA is not distorting the data. It is choosing the basis in which the covariance geometry is already aligned with the axes.
Whitening rescales the geometry
After PCA, the covariance becomes diagonal but the variances may still be unequal. Whitening applies one more transformation:
Interpretation:
- rotate into principal directions;
- divide each direction by its standard deviation.
After whitening, every principal direction has variance , so the covariance becomes the identity matrix.
Worked Example
Suppose
Then the covariance lengths are
The correlation is
So the angle between the centered variables is
This is the same geometry you already know from a -- triangle: the variables are fairly aligned, but not identical.
That is the payoff of this lesson. A familiar geometric computation now has a statistical interpretation.
Why This Shows Up In ML
This viewpoint matters in machine learning because many standard preprocessing and modeling steps are really geometric operations in disguise.
Examples:
- PCA rotates into principal directions.
- Whitening removes covariance and standardizes scale.
- Feature normalization improves conditioning for optimization.
- Latent representations are often compared by covariance structure rather than by raw coordinates.
Once the covariance geometry is visible, many algorithms become easier to motivate and easier to debug.
Exercises
- If
compute the correlation and say whether the corresponding angle is acute or obtuse.
-
Build the covariance matrix from those three quantities. Why must the matrix be symmetric?
-
Explain, without calculation, why PCA makes the covariance matrix diagonal in the principal-component basis.
-
In your own words, what does whitening change that PCA alone does not?
Implementation Exercise
Create a tiny TypeScript experiment with a two-dimensional dataset.
- Compute the covariance matrix.
- Hard-code or compute its orthonormal eigenvectors.
- Rotate the centered points into the principal basis.
- Rescale each rotated coordinate by the reciprocal of its standard deviation.
Print the covariance before PCA, after rotation, and after whitening. The goal is to see the sequence:
- tilted ellipse;
- axis-aligned ellipse;
- sphere-like cloud.
Reflection Questions
- Does correlation feel more natural when read as cosine?
- Why is covariance the right notion of orthogonality here instead of ordinary Euclidean dot product on raw coordinates?
- Which step in whitening is doing the “rotation” job, and which step is doing the “unit variance” job?
- If you had to explain PCA in one sentence now, would you say “maximize variance” or “diagonalize covariance”?
Completed Exercises
Handwritten work submitted after completing this lesson.













