Too many features
Each student is a row of data with two features: a maths score and a physics score, out of 10. Two features means two dimensions, so each student is a point on a flat chart. Real data often has hundreds.
The scores rise together: good at maths usually means good at physics. The points hug a slanted line. Dimensionality reduction keeps most of the information with fewer features: here, one number per student instead of two.
Finding PC1
Principal component analysis (PCA) is the classic method. Step one: subtract the mean. The average student scored 6 and 6, so student A's (3, 4) becomes (−3, −2). Now every point is measured from the centre, the cross.
Draw a line through the centre and drop each point onto it at a right angle. The variance (spread) of the landing spots depends on the angle: along the maths axis it is 4.0. Turning the line changes it.
At 45° the spread peaks at 7.6. The direction of greatest variance is the first principal component, PC1. It points along (0.71, 0.71): both scores up together, a kind of overall score.
Each student's new feature is where they land on PC1: z = 0.71 × maths + 0.71 × physics, both centred. Student A lands at −3.54. Two numbers became one.
The leftover direction, at right angles, is PC2. Its variance is only 0.4: the short drop lines are all we throw away. PC1 keeps 7.6 of the total 8.0, that is 95% of the variance, with half the numbers.
In practice
The whole method is six lines: centre, build the covariance matrix, take its eigenvectors, keep the one with the largest eigenvalue, project. With hundreds of features you keep the top k eigenvectors instead of one.
Fewer features train faster, filter out noise and can be plotted: 64-pixel images of digits become dots on a 2D chart. The catch: scale features first when their units differ, and PCA only finds straight-line directions.
What happens
;; step 1/9 · features student maths physics A 3 4 B 5 4 C 6 5 D 6 7 E 7 7 F 9 9 features = columns; 2 features = 2 dimensions
The six students are invented for the lesson. Both scores have the same variance, so PC1 lies at exactly 45° and keeps exactly 95% of the variance; real data is rarely this tidy. The line of greatest variance is also the line closest to the points: it makes the squared drop lines as short as possible, which is how Pearson first described it in 1901.