Interactive demo · Applied Statistical Learning in R and Python · Chapter 12

K-means against hierarchical clustering: nested or not

Cutting a dendrogram gives clusters for every K at once, and they are nested: the K-cluster solution always splits one cluster of the (K − 1)-cluster solution. The best K-means partitions are not tied together in this way. The book's example is a group of men and women from three countries: the best split into two may be by sex and the best split into three by country, and no tree can show both. Choose a data set, a linkage and K, and compare the two methods' clusters, their within-cluster variation (12.17), and whether each K-means solution is nested in the one before.

Data set

Number of clusters K

Linkage (hierarchical)

Try these

K-means: Algorithm 12.2 from 50 random starts (K observations drawn at random, spread out as in k-means++, as first centroids; fixed seeds), each finished by single-observation moves that lower (12.17) further (as R's kmeans() does), keeping the run with the smallest (12.17). Hierarchical: Algorithm 12.3 on Euclidean distances, cut by undoing the last K − 1 fusions. Both use all the variables; the plots show two of them (people: the two country coordinates, sex being the third, hidden axis; filled dots are women, rings men) or the first two principal component scores (USArrests, NCI60).

In the lecture notes