Lecture 14 · room 202
HEMA · Università Cattolica del Sacro Cuore, Rome
Monday 16 November 2026
Lecture 13 · Lab: clustering end to end · Fri 13 Nov
| Time | Min | |
|---|---|---|
| 17:00 | Last time · questions | 10’ |
| 17:10 | The idea: a component is a direction, by hand | 50’ |
| 18:00 | Break | 10’ |
| 18:10 | How many components, and what they mean | 30’ |
| 18:40 | Compression as a model | 10’ |
| 18:50 | Set 12 | 10’ |
Twenty questions, three answers
In each case the data are wide and redundant. PCA finds the few directions along which they actually vary, and throws away the rest.
Stated without matrices first
Picture the data as a cloud of n points in p dimensions.
Each point’s score is its coordinate along that line. Each variable’s loading is how much it contributes to the direction.
Note
Nothing is dropped, yet. PCA is a rotation. Compression happens when you keep the first few components and discard the others — and you decide how many.
A line turns through the cloud while the variance of the projection is measured at every angle. It stops where that number is largest. The first component is not a metaphor about spread — it is the argument of a maximum, and this is that maximum being found.
For centred data X (n \times p), the first component is the unit vector \phi_1 that maximises the variance of the projection:
\phi_1 = \arg\max_{\lVert \phi \rVert = 1} \; \operatorname{Var}(X \phi)
Everything you will read off a PCA is one of: a loading vector \phi_k, a score X\phi_k, or a variance share \lambda_k / \sum \lambda.
Height and arm span, standardised, for four people: (-1.5,-1.5), (-0.5,-0.5), (0.5,0.5), (1.5,1.5).
Two variables, one component, 100% of the variance. You had two columns and one piece of information. That is the whole method, in the simplest case it can be seen in.
Four people, every score computed, and a second component whose variance is exactly zero. When two columns say the same thing, PCA says so with a number.
PCA is a variance-hunter. A variable measured in thousands is the first component, whatever it means.
scale. = TRUE — unless every column is already in the same unit and you want the large-variance ones to dominateAttention
Same trap as clustering, same fix, same reason. Distance and variance are both blind to units.
They disagree often. When they do, prefer the smaller number you can interpret. A component nobody can name is not a driver; it is noise with a label.
The same scree plot under the three rules you were just given. They disagree, and no amount of staring resolves it. The choice is yours to make and yours to defend — which is why the exercise asks for the sentence, not the number.
Read its loadings. Large positive and large negative loadings tell you what the direction contrasts.
| Item | PC1 | PC2 |
|---|---|---|
| Staff courtesy | 0.48 | 0.05 |
| Waiting time | 0.45 | −0.10 |
| Clarity of explanations | 0.47 | 0.02 |
| Price fairness | 0.08 | 0.71 |
| Value for money | 0.11 | 0.68 |
PC1: service experience. PC2: price perception. Two drivers, from five items — and now a regression of satisfaction on two scores instead of five collinear columns.
library(tidyverse); library(factoextra)
X <- USArrests # 50 states, 4 crime rates + urban pop
pca <- prcomp(X, scale. = TRUE)
summary(pca) # variance explained, cumulative
fviz_eig(pca) # scree
pca$rotation # loadings: variable × component
head(pca$x) # scores: state × component
fviz_pca_biplot(pca, repel = TRUE) # both at once — the plot to showNote
On USArrests, PC1 loads on all three violent-crime rates: overall crime. PC2 is urban population alone: urbanisation. Two components, 87% of the variance, and both have a name.
It is the single most information-dense plot in this course. Spend the lab learning to read one.
Keep q < p components. From the scores you can rebuild an approximation of every row:
\hat X \;=\; (X \Phi_q)\, \Phi_q^\top
Note
Hold this thought for week 5. A neural network that learns to compress its input to q numbers and rebuild it is called an autoencoder — and with linear activations, it is PCA. Nonlinear activations make it a PCA that can bend.
prcomp on USArrests, with and without scale. = TRUE. Compare the first loading vector. Which state moved most?customers.csv from Friday: PCA on the six behavioural columns. How many components for 80%? Name PC1 and PC2 from the loadings.kmeans on the first two scores instead of all six columns. Same segments?Principal components · about 40 minutes · before Tue 17 Nov
Not graded. The test is a mirror, not an exam.
USArrests example is the one we ran?prcomp, factoextra::fviz_pca_biplotStatistics & Big Data · HEMA, Università Cattolica del Sacro Cuore