Contents
02What clustering is
2.1Unsupervised grouping
Clustering is unsupervised learning: there is no answer key. We want groups in which points of the same group are similar and points of different groups are different. A bank, for instance, describes each of its millions of customers by numbers such as the balance, the monthly card spending and the number of logins per month; clustering can reveal segments such as savers, big spenders and dormant accounts, so that each group can be offered the right product. Biologists cluster genes with similar expression profiles across experiments, astronomers cluster stars and galaxies, search engines cluster news stories about the same event, and image software clusters pixel colours to compress a picture (Section 3).
Because there are no labels, there is also no single correct answer. Sorting a drawer of socks by colour, by size or by owner gives three valid clusterings of the same socks. A clustering method therefore always starts from a definition of similarity, and Hastie et al. (2009, Section 14.3) stress that this definition “can only come from subject matter considerations”, much as the loss function of a supervised problem does. In this tutorial each algorithm is presented as one definition plus a way to compute it.
2.2Distances depend on units: standardize first
Most methods compare points by Euclidean distance, and that distance depends on the units of each feature. A feature measured in dollars, with values in the tens of thousands, swamps one measured in logins per month. The usual fix is to standardize each feature, z=(x-m)/s with m and s the feature’s mean and standard deviation, so that every feature has mean 0 and variance 1 and gets an equal say.
Worked example 1. The video shows three customers: #10234 (balance $82,400, card spending $310 per month, 12 logins), #20981 ($2,150, $4,870, 41 logins) and #33017 ($640, $0, 0 logins). In raw units the distances are 80{,}379 between the first two, 81{,}761 between the first and the third, and only 5{,}099 between the second and the third, so the big spender and the dormant account look like close neighbours. The balance difference makes up 99.7\% and 99.999\% of the squared distance in the two pairs involving the saver: the other features hardly count. Standardizing each feature with the mean and standard deviation of these three customers (for the balance, 28{,}396.7 and 38{,}191.1) changes the picture: the distances become 3.38, 2.26 and 3.23, and now the saver and the dormant account are the closest pair, since both spend little and rarely log in. Which answer is right depends on what the bank wants; the point is that the units, not the customers, decided the first one.
Standardizing is a default, not a law. If one feature genuinely matters more, it can be given more weight; and standardizing a feature that is pure noise inflates it to the same importance as an informative one.
2.3How hard is clustering?
A natural objective, used by K-means and Ward’s method, is the within-cluster scatter. Hastie et al. (2009, Section 14.3.5) point out that the total scatter T=\frac12\sum_{i}\sum_{i'}\|x_i-x_{i'}\|^2 splits as T=W(c)+B(c) into pairs inside the same cluster (W) and pairs in different clusters (B); since T does not depend on the clustering, making clusters tight (W small) is the same as making them well separated (B large). We could find the best clustering by trying them all, but the number of ways to split n points into K non-empty groups is the Stirling number of the second kind,
which is 34{,}105 for n=10, K=4, already 11{,}259{,}666{,}950 for n=19, and about 8.5\times10^{67} for the 144 points and 3 clusters of the video’s K-means scene. Minimizing (1) exactly is NP-hard (Aloise et al., 2009). Every practical algorithm is therefore a clever search that examines a tiny fraction of the possibilities, and most of them can only promise a local optimum.
Pause and think. Why can we not choose the number of clusters K by minimizing J in (1)?
Show the answer
Because J can only go down as K grows: with one more centre, every point can keep its old centre or switch to a closer one. With K=n every point is its own cluster and J=0. Choosing K needs a criterion that penalizes complexity or measures separation (Section 4).