Classical machine learningML 12

Principal Component Analysis

Data with many features are hard to look at. Principal component analysis (PCA) finds the directions in which the data vary most, the principal components, each at right angles to the ones before. Describing the data along the first few of them often keeps most of the information in far fewer numbers, so PCA is used to draw high-dimensional data in two dimensions, to compress it, and to remove redundant, correlated features before other methods. No labels are involved. The first part shows the idea with two measurements; the second applies it to a fictional panel of eight lab results.

1 · Two features: finding the axes

height and weight of 60 adults, centred on the meandrag points
click: add point · drag: move (in the unrotated view) · arrows: 2 standard deviations along each component

orange: PC1, the direction of greatest spread · purple: PC2, at right angles to it · “keep only PC1” slides every point onto the PC1 line along the dotted lines: those distances are what is lost

2 · Many features: a lab panel in two dimensions

150 patients, 8 measurements each
points: patients · arrows: how each measurement points in this view

Variance explained a scree plot

colour and shape: healthy · metabolic syndrome · kidney disease: added afterwards for reading the plot; PCA never saw them

What the components are

PCA centres the data and looks for the line through the middle along which the points are most spread out: PC1. It is also the line that the points are, on average, closest to, which is how Karl Pearson framed it in 1901. PC2 is the direction of greatest remaining spread at right angles to PC1, and so on. Mathematically the components are the eigenvectors of the covariance matrix and each eigenvalue is the variance along its component; the rotation they define keeps all the information, and dropping the last components throws away only the variance along them. Height and weight are strongly correlated, so PC1 (roughly “overall size”) carries most of the variance, and keeping only PC1 loses little. This first part is not standardised, so the direction of PC1 depends on measuring in centimetres and kilograms: in metres and pounds it would tilt differently. The second part shows why that matters.

Reading a biplot, and why to standardise

In the lab panel, each arrow shows how one measurement lines up with the two components on screen: measurements whose arrows point the same way rise and fall together, and patients lie towards the arrows of their high values. With standardisation, PC1 picks up the metabolic measurements (weight, waist, glucose and triglycerides up, HDL down) and separates the metabolic-syndrome group, while PC2 combines body size and kidney function. Turn standardisation off and PC1 becomes almost pure creatinine, with over 90% of the variance, simply because creatinine is measured in µmol/L and its numbers are the largest. Without standardising, PCA ranks features by their units, not by what they tell you, so features on different scales are almost always standardised first.

Limits

PCA only finds straight directions, and the direction of greatest variance is not necessarily the most useful one: here the kidney-disease group differs from the healthy group mainly along PC2 and PC3 (show PC2 against PC3), which together carry less than 40% of the variance. Components are mixtures of every feature, which can make them hard to name. Methods such as t-SNE and UMAP draw curved, local structure better, but distort distances in ways that are easy to over-read. PCA remains the usual first look at a new dataset, and the word2vec demo uses it to draw 300-dimensional word vectors in three.

References

  1. Pearson, K. (1901). On lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 2(11), 559–572. doi.org/10.1080/14786440109462720
  2. Hotelling, H. (1933). Analysis of a complex of statistical variables into principal components. Journal of Educational Psychology, 24(6), 417–441, and 24(7), 498–520. doi.org/10.1037/h0071325
  3. Jolliffe, I. T., & Cadima, J. (2016). Principal component analysis: a review and recent developments. Philosophical Transactions of the Royal Society A, 374(2065), 20150202. doi.org/10.1098/rsta.2015.0202