Unsupervised Learning: Structure Without Labels
What changes when there is no response to predict: principal components as the direction of maximum variance, K-means and the local optima it settles into, hierarchical clustering and the linkage that decides the answer - and why none of the required choices can be validated the way a classifier can.
Prerequisites: The Bias-Variance Tradeoff
Every method up to this point has had a response to predict, and that response has been doing more work than it looks. It defines what the model is estimating, it makes a held-out error meaningful, and it settles every tuning decision by cross-validation. Remove it and all three go at once.
Unsupervised learning is what remains: only , and the question of what structure it contains. This article covers the three standard answers and is honest throughout about the thing that makes them harder to use than anything in the supervised path - there is nothing to check them against.
A. Principal components: the direction of maximum variance
The first principal component is the normalised linear combination
with the largest variance. The constraint carries real weight: without it you could double every , quadruple the variance, and repeat without limit, so no maximum would exist. Fixing the length to one makes the question one of direction.
There is a second, equivalent description worth holding onto, because it is the one that makes PCA feel geometric rather than algebraic: the same direction is the line closest to all observations, measured by squared perpendicular distance. The total variance is fixed, so whatever the projections fail to capture is left over as distance to the line - maximising one and minimising the other are one problem.
A worked example
Six observations on two variables:
The eigenvalues of are and , and the first loading vector is . Projecting the centred data onto gives scores whose variance is - the eigenvalue is the variance its component captures, which is why the proportion of variance explained can be read straight off:
One direction carries 98.83% of the variation. A scree plot orders these and the usual advice is to look for an elbow - which is an eyeball judgement, not a test. There is no widely accepted objective rule for how many components to keep, and this is the first place the missing response is felt.
Loadings are not scores. A loading says how much a variable contributes to a component and belongs to the dataset as a whole; a score says where an observation sits along it. Confusing them is the most common way to misread a PCA output.
PCA is also not scale invariant. Variance carries the square of the units, so recording a length in millimetres rather than metres multiplies its variance by and hands that variable the first component for no reason but the choice of ruler. Standardise each variable to standard deviation one first - unless the variables already share units and their differing variances are genuinely meaningful, in which case scaling discards real information.
B. K-means, and the local optimum it settles into
K-means partitions the observations into exhaustive, non-overlapping clusters, minimising the total within-cluster variation
Dividing by matters: a cluster of points has ordered pairs, so an undivided sum would penalise large clusters for their size rather than their spread.
There are ways to assign observations to labelled clusters, and about distinct partitions once the labels are ignored, so the exact problem is not solved but approximated. The algorithm assigns at random, then alternates: compute each cluster's centroid, and reassign each observation to the nearest one. It converges because neither step can increase the objective - the centroid minimises squared deviations, and moving a point to a nearer centroid cannot make things worse - and there are finitely many partitions.
It converges. That is not the same as being right.
Take seven points and :
Exhaustive search over all assignments gives the global optimum with .
Now start from . The centroids are , and , and every point is already assigned to its nearest centroid - so the first pass changes nothing and the algorithm halts immediately, reporting
nearly thirty times worse. Nothing is broken: convergence to a local optimum is all the method promises, and the failure is silent.
Runs in your browser. The first run downloads the Python runtime (~10 MB), then it is cached.
So K-means is run many times from different random starts and the best result kept. That is part of the method, not a refinement for when you have time. And itself cannot be chosen by the objective, which falls monotonically as rises and reaches zero when every observation is its own cluster.
C. Hierarchical clustering, and the linkage that decides the answer
Agglomerative clustering removes the need to commit to : start with every observation alone, repeatedly fuse the two least dissimilar clusters, and record the height at which each fusion happened. Cutting the resulting dendrogram horizontally gives a clustering, so one tree contains an answer for every .
Two cautions. First, the clusterings are nested by construction - if the true grouping is not, no cut will recover it. Second, and the usual misreading: only fusion height measures similarity. Horizontal position means nothing, and two adjacent leaves may fuse only at the very top.
Fusing needs a dissimilarity between groups, and the choice is the linkage: complete takes the largest distance between the groups, single the smallest, average the mean, centroid the distance between centroids.
The same points, two different answers
Ten points: a compact group of three, a compact group of three, and four evenly spaced points bridging them.
| Linkage | Cut into two | Sizes |
|---|---|---|
| Complete | left group plus two bridge points, against the rest | 5 and 5 |
| Average | the same | 5 and 5 |
| Single | the right group alone, against everything else | 3 and 7 |
Single linkage needs only one close pair, so each bridge point attaches to the growing blob in turn and the chain drags an entire group along - a trailing cluster. Complete and average linkage look at the largest and mean distances, refuse to fuse groups that are far apart overall, and split the data down the middle. This is the general pattern, which is why complete and average linkage are generally preferred; centroid linkage has a defect of its own, an inversion, where two clusters fuse below the height of one of them.
Runs in your browser. The first run downloads the Python runtime (~10 MB), then it is cached.
Those are the same ten points below, clustered four ways. Switch the linkage and watch the colours move: single linkage drags the whole bridge into one cluster of seven, complete and average refuse and split down the middle. Nothing in the data prefers one answer, which is the uncomfortable part. The second dataset is three points and exists for honesty - centroid linkage produces no inversion on the ten, so pointing at them and claiming one would be claiming something they do not show. On three points it does, and the fusion heights say so.
Interactive: the same points, four answers
Nothing in the data chooses the linkage. Everything else follows from it.
- Clusters
- 2
- Sizes
- 3 + 7
- Last fusion height
- 1.746
- Inversions
- 0
Single linkage fuses on the smallest distance, so each bridge point attaches to whatever blob is nearest and the chain drags the left group and the entire bridge into one cluster of 7. That is a trailing cluster, and it is the general tendency rather than a quirk of these ten points. Switch to complete or average and the same data splits down the middle.
D. What is actually missing
Collect the decisions this article has required: whether to standardise; how many components to keep; how many clusters; which dissimilarity measure; which linkage; where to cut. Every one changes the answer, and not one of them can be settled from inside the data.
In the supervised path each would have been a straightforward cross-validation against a held-out response. Unsupervised learning has no response to hold out, which is what James et al. mean by calling these small decisions with big consequences. The consequence for practice is a discipline rather than a technique: try several sensible sets of choices, and report the structure that appears under most of them - rather than presenting a single run as the answer.
The training path Unsupervised Learning works through the same three methods with the derivations in full, and the encyclopedia entries Principal Component Analysis and K-Means Clustering cover them as references.
References & further reading
- Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani, An Introduction to Statistical Learning, with Applications in R, Springer (Springer Texts in Statistics 103), 2013source ↗
Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.