PCA: Find the Shadow
Move the light until the data cast their widest shadow
Game instructions
The points form an object in three dimensions. A distant light source sends parallel rays through the object onto a screen.
Move the light around the object. Find the shadow that preserves as much variation as possible, then lock your answer.
After the reveal, PCA shows its own projection, PC1 and PC2, and their component coefficients. The explanation below the game shows how those coefficients determine where a shadow lands.
Move the sun
PCA reveal
Component directions
| Variable | PC1 | PC2 |
|---|---|---|
| X1 | -- | -- |
| X2 | -- | -- |
| X3 | -- | -- |
These are unit direction-vector coefficients. Larger absolute values mean the component points more strongly along that original axis. Reversing every sign gives the same PCA axis.
How does PCA make the shadow?
Start with one ordinary shadow. No PCA yet. Once that geometry is clear, PCA is mostly the same calculation repeated for many points while choosing the direction that makes their shadows spread out.
1. One point, one shadow
Put one point at P = (3, 4). Now cast its shadow onto a line tilted 30° above the X axis. The question is simply: where on that line does the shadow land?
Projection angle θ = 30°
Direction = (cos 30°, sin 30°)
= (0.866, 0.500)
2. Cosine gives the shadow length
A shadow keeps only the part of the point that points along the chosen direction. In coordinates, add the X part and the Y part that point along the tilted line.
= 3 cos 30° + 4 sin 30°
= 3(0.866) + 4(0.500)
= 4.60
3. PCA asks which angle gives the widest shadows
With many centred points, every possible angle gives a different set of shadow positions. PCA chooses the angle for which those positions have the largest variance.
sₓ² = Σx²/(n-1) = 3.25
sᵧ² = Σy²/(n-1) = 1.75
sₓᵧ = Σxy/(n-1) = 1.30
θ = ½ atan2(2sₓᵧ, sₓ² - sᵧ²)
θ = 30°
4. The PCA coefficients tell us where the axis points
Once PCA has found θ, the PC1 direction is just a unit arrow. Its coefficients are the trigonometric parts of that arrow along the original axes.
= (cos 30°, sin 30°)
= (0.866, 0.500)
score = 0.866x + 0.500y
5. Three dimensions use exactly the same idea
In the game a point has three centred coordinates. PC1 is a unit direction (a, b, c), so its three coefficients are direction cosines with X1, X2 and X3.
PC1 = (0.667, 0.667, 0.333)
PC1 score = 3(0.667) + 1(0.667)
+ 2(0.333) = 3.33
6. Two scores tell us where the 2D shadow lands
Repeat the same projection onto PC2. Those two signed shadow lengths become the coordinates on the PCA screen.
PC2 score = -1.41
position on PCA screen
= (PC1 score, PC2 score)
= (3.33, -1.41)