2.5.10 · D1Unsupervised Learning

Foundations — Explained variance and choosing components

2,389 words11 min readBack to topic

Before we can talk about "explained variance," we must earn every symbol the parent note throws at you. We go from a picture of raw data all the way to the eigenvalue ratio — never using a symbol before it has a plain meaning and a picture.


[!definition] Symbol 1 — A data point and a data cloud

A data point is one measured thing described by several numbers. Measure a person's height and weight and you get two numbers: that pair is one point in a 2D plane.

Stack many such points and you get a data cloud: a scatter of dots. The parent topic is entirely about the shape of this cloud.

Figure — Explained variance and choosing components

[!definition] Symbol 2 — , , and the matrix

  • = the number of data points (how many dots).
  • = the number of measurements per point (the number of axes / dimensions).

We line the points up into a grid of numbers called : one row per point, one column per measurement. So is an grid (" tall, wide").

Why the topic needs it: everything else — averages, spread, covariance — is computed by sweeping over these rows and columns.


[!definition] Symbol 3 — The mean and "centering"

The mean of column , written (say "x-bar-j"), is the average of that one measurement across all points:

Here the symbol is just shorthand for "add up as counts from 1 to ." It is a compact "add all of these" instruction, nothing more.

Centering means subtracting each column's mean from that column, so every measurement now describes how far from average a point is. From now on, whenever we write in a variance or covariance formula, we assume has already been centered — every column mean is .

Figure — Explained variance and choosing components

[!definition] Symbol 4 — Variance

Variance measures how spread out one measurement is. For centered data (mean already zero) it is the average of the squared distances from the middle:

  • We square so that being below average (a negative gap) counts the same as being above (a positive gap) — squares are never negative.
  • Big variance = the dots are smeared far along that axis. Zero variance = every point has the same value there (a flat, dead direction).

[!definition] Symbol 5 — Total variance and the trace

Total variance is the sum of the variances of every measurement — one number describing the whole cloud's total spread:

There is a name for "add up the diagonal of a square grid": the trace. For any matrix ,

i.e. sum the entries running top-left to bottom-right. We meet trace here because — as we will see in Symbol 7 — the diagonal of the covariance matrix holds exactly the per-axis variances, so total variance = trace of the covariance matrix. Think of total variance as the full pie of spread that we will later slice into pieces.


[!definition] Symbol 6 — Vectors and projection

A vector is an arrow pointing in some direction. When we make its length exactly 1 we call it a unit vector, written with the property (more on the below — it just means "the arrow dotted with itself gives length-squared = 1").

Projection answers: "If I shine a light straight down onto the line pointing along , where does each dot land?" Each landing position is a single number: how far along that point sits. Collecting all these numbers for every point is written .

Figure — Explained variance and choosing components

The transpose simply means "flip the grid over its diagonal" — rows become columns. We need it so that quantities like read as "multiply the shadow-list by itself," which is exactly how you get a sum of squares — i.e. a variance.


[!definition] Symbol 7 — The covariance matrix

The covariance matrix is the grid built from the centered data:

Let us open up one entry to see what it means. The matrix product has, in row and column , the dot product of column of with column . So:

Read that entry aloud: "average, over all points, of measurement times measurement ." Because is centered, this is exactly the covariance of measurements and — how they vary together. (If were not centered, this sum would be a raw cross-product, not a covariance — which is why centering was mandatory.)

  • Diagonal (): — the per-axis variances. So , confirming Symbol 5.
  • Off-diagonal (): how two measurements move together (do height and weight rise as a pair?).

Why the topic needs it: the whole PCA story lives inside . The stretch directions of the cloud and the amount of stretch are hidden in this one grid — and eigenvalues pull them out.


[!definition] Symbol 8 — Eigenvectors and eigenvalues

For the matrix , an eigenvector is a special direction that does not rotate — it only stretches it. The stretch factor is its eigenvalue, written ("lambda-i"). See Eigenvalues and Eigenvectors.

Read this aloud: "applying to the special arrow gives back the same arrow, just scaled by ."

Figure — Explained variance and choosing components

[!formula] Symbol 8b — WHY the eigenvalue is the variance along

We claimed equals the variance of the data projected onto . Let us earn it, one step at a time.

Step 1 — write the variance of the shadows. The projected data is the list (Symbol 6). Its variance, since it is already centered, is the average of its squared entries, which the transpose packs neatly as:

What this looks like: take the shadow positions in the s03 figure, square them, average them.

Step 2 — regroup the transpose. A rule of transposes: . Applying it to :

Step 3 — spot the covariance matrix. But is exactly (Symbol 7). Pulling the inside:

Step 4 — use the eigenvector property. Since :

using from the orthonormal box. Done: . The eigenvalue is the variance along its direction — no metaphor, an equation.


Symbol 9 — Assembling the explained-variance ratio

Now every symbol in the parent formula is earned:

It is literally "how big is my slice compared to the whole pie." Adding the first slices gives the cumulative explained variance — the fraction of the cloud's spread you keep if you drop everything past component . That is the number you threshold at 95% when doing Dimensionality Reduction.

The same eigenvalues also appear (as squared singular values) inside Singular Value Decomposition (SVD), and the "which columns matter" question links to Feature Selection vs. Feature Extraction. The visual ranking of is drawn in a Scree Plot.


Prerequisite map

Data point and data cloud

Matrix X with n and d

Mean and centering

Variance per axis

Total variance and trace

Vector and projection Xv

Covariance matrix C

Eigenvectors and eigenvalues

Explained variance ratio

Choosing number of components

Read top to bottom: raw dots become a matrix, centering fixes the middle, variance measures spread, projection and covariance package the shape, eigenvalues slice the spread, and the ratio decides how many components to keep.


[!recall]- Quick checks as you build

Cloze yourself before moving on.

The average of squared gaps from the middle is called
variance
The grid of numbers with one row per point and one column per measurement is
the data matrix
Subtracting each column's mean so the cloud sits on the origin is called
centering
Shining a light onto a direction and recording where each dot lands is called
projection ()
A direction that only stretches, never rotates, is an
eigenvector
The stretch factor of an eigenvector equals the
variance of the data along that direction (its eigenvalue )
Adding up the diagonal entries of a square matrix is called the
trace
The sum of all eigenvalues equals the
trace of , which equals the total variance in the data

Equipment checklist

Test your readiness — cover the right side and answer.

I can read and say which point and which measurement it is
Row = the point, column = the measurement
I know why we square the gaps in variance
So below-average and above-average gaps both count positively; squares are never negative
I can explain "variance = information" in one sentence
A direction where points differ carries the differences that matter; a flat direction distinguishes nothing
I can describe projection as a picture
The list of shadow positions when every dot is dropped straight onto the line along
I can write the entry of the covariance matrix
— the covariance of measurements and (needs centered )
I can walk the algebra
I know why eigenvectors can be taken orthonormal
is symmetric; symmetric matrices have orthonormal eigenvectors ()
I know what "trace" means and why it equals total variance
Sum of the diagonal; the diagonal of holds the per-axis variances, and trace = sum of eigenvalues
I can state the EVR formula and name every symbol
— one eigenvalue's slice over the sum of all eigenvalues (the total variance)