2.5.10 · D4Unsupervised Learning

Exercises — Explained variance and choosing components

2,030 words9 min readBack to topic

These problems build on the parent topic. Each is labelled L1 → L5 by cognitive demand. Try each one before opening the solution. Every symbol you need was defined in the parent note; a quick reminder of the two workhorses:

  • = the eigenvalue of principal component = the amount of variance (spread) the data has along that direction. Bigger = more spread = more information. (See Eigenvalues and Eigenvectors.)
  • = the fraction of all the variance living in component .
  • = the fraction you keep after taking the first components.

Level 1 — Recognition

Exercise 1.1

Given eigenvalues , what is the total variance in the data?

Recall Solution

Total variance is just the sum of all eigenvalues (from Step 3 of the parent note: ). What we did: added every eigenvalue. Why: the parent derivation showed each is the variance along one principal axis, so their sum is the whole spread.

Exercise 1.2

For the same eigenvalues , compute as a percentage.

Recall Solution

The first (largest) component alone captures 60% of the spread.

Exercise 1.3

True or false: eigenvalues in a PCA scree plot are always listed in descending order.

Recall Solution

True. PCA sorts components so . That ordering is what makes the Scree Plot slope downward and lets us stop early once returns get small.


Level 2 — Application

Exercise 2.1

A 4D dataset has eigenvalues . Compute all four and .

Recall Solution

Total . Keeping the first two components retains 80% of the information.

Exercise 2.2

Using the eigenvalues from 2.1, how many components are needed to reach at least 90% cumulative variance?

Recall Solution

March through the cumulative sums: , so we need components. Why we stop at 3: the algorithm accumulates variance in importance-order and halts the first time it crosses the threshold — going to (80%) is not enough, (95%) clears the bar.

Exercise 2.3

A diagonal Covariance Matrix is What fraction of variance is lost if you drop the smallest component?

Recall Solution

For a diagonal covariance matrix the diagonal entries are the eigenvalues: , total . The smallest is , so the fraction lost is You keep .


Level 3 — Analysis

Exercise 3.1

Two datasets both have total variance .

  • Dataset A:
  • Dataset B:

For a 90% retention target, which dataset compresses better (needs fewer components)? Explain geometrically.

Recall Solution

Dataset A cumulative: → needs 3 components for 90%. Dataset B cumulative: → needs 4 components for 90% (three give only 75%). A compresses better. Geometrically (see figure below): A's variance is concentrated — the data cloud is a stretched cigar lying mostly along a couple of directions, so a few axes capture almost everything. B's variance is spread evenly — the cloud is a round ball with no preferred direction, so every axis is equally important and you cannot throw any away cheaply.

Figure — Explained variance and choosing components

Exercise 3.2

A dataset has eigenvalues where the top 3 are and the remaining 47 eigenvalues are each exactly Actually the remaining 47 sum to . What is , and what does a Scree Plot "elbow" tell you here?

Recall Solution

Total . The elbow is at component 3: the first three eigenvalues drop steeply (), then the curve flattens into a long tail of tiny, nearly-equal eigenvalues. That flat tail is the classic signature of noise — many directions each carrying a sliver of variance. The elbow says "structure lives in the first 3; the rest is a haze." (Note the tension: the elbow suggests but that only gives 70% — thresholds and elbows can disagree.)


Level 4 — Synthesis

Exercise 4.1

You compute PCA two ways on the same centered data matrix (, with samples): (a) eigen-decomposition of the covariance matrix giving eigenvalues ; (b) Singular Value Decomposition (SVD) of giving singular values . Show the relationship between and , and rewrite using singular values.

Recall Solution

SVD writes . Then (using ). This is exactly the eigen-decomposition of , so its eigenvalues are , and the covariance eigenvalues are Substituting into the ratio, the cancels top and bottom: Why this matters: you can get explained variance straight from singular values without ever forming the covariance matrix — numerically safer and often faster.

Exercise 4.2

A dataset's singular values are and samples. Compute the covariance eigenvalues and the total variance, then .

Recall Solution

Using with : Total variance . Equivalently via singular values directly: — identical, as proven in 4.1.


Level 5 — Mastery

Exercise 5.1

Design a retention policy. You have a 50D dataset. Below is a partial cumulative table. Your team needs 95% variance retained, but each kept component costs compute. Given (entries are ), find the smallest meeting 95%, and argue whether jumping to that from the previous one is "worth it."

Recall Solution

Scan for the first entry :

  • (below), (first to cross).

So the smallest is . Marginal analysis: the jump from to adds percentage points for one extra component — a modest but real gain that pushes you over the required 95% line. Since the requirement is a hard constraint, that 8th component is mandatory regardless of its small marginal value. Going to (adds only ) would be optional over-spending, since 95% is already satisfied at .

Exercise 5.2

Conceptual synthesis. PCA is feature extraction, not feature selection. Suppose two ORIGINAL features are perfectly correlated (each has variance 5, correlation ). What does the covariance eigen-structure look like, how much can you compress, and why is this extraction rather than selection?

Recall Solution

With variance 5 each and correlation 1, the covariance , so Eigenvalues: trace , , so .

  • , .
  • You can drop to 1 component with zero information loss — the two features were redundant copies along one line.

Why extraction, not selection: the single surviving component is the direction — a new feature built as a combination of both originals. Dimensionality Reduction by PCA never picks or ; it manufactures a fresh axis. Feature selection would have kept one raw column and thrown the other away. Here they give the same numerical span, but the mechanism (blend vs. keep-one) is the defining difference.