Cluster analysis
Intermediate
What you need first. Nothing else on this path comes first. This page is part of Statistical learning.
In statistical learning, cluster analysis is the grouping of observations so that members of one group are closer to each other than to members of another group. A file of measurements often looks smoother once the rows are gathered into a few bundles. Cluster analysis is the set of methods that make those bundles from the measurements alone, so that rows in one bundle are closer to each other than to rows placed elsewhere.[1] [2]
Cluster analysis
| Fact | Value |
|---|---|
| Topic | Statistical learning |
| Listed on | Statistical learning |
| Worked example | 1 |
Motivating example
Four points in the plane are enough to see the choice. Place at , at , at and at . Nothing in the file says which points share a label. A grouping that first joins with , and with , is using distance. A grouping that cuts the plane at is using a different summary of the same four points. Cluster analysis is the family of such groupings, not any one cut.[3] [2]
Definition
Cluster analysis, also called data segmentation, groups objects so that those inside a cluster are more closely related than objects assigned to different clusters. An object may be described by its measurements or by its relations to the other objects. A second goal is a hierarchy: clusters themselves are grouped so that, at each level, members of a branch are more similar than members of different branches.[1]
The same idea can be stated with a distance. Clustering partitions a data set into subsets so that association is strong inside a subset and weak between subsets, for a distance or similarity that has been defined. The two organisations named there are partitional clustering and hierarchical clustering.[3]
Closeness has to be supplied. Euclidean distance is one choice; a correlation between profiles is another. Once closeness is fixed, two organisations are common. One chooses a number of groups in advance and partitions the points. The other joins groups step by step and keeps every intermediate partition. The first is K-means. The second is hierarchical clustering. They answer different questions about the same distances.[2] [1]
K-means partitions the observations into a pre-specified number of non-overlapping clusters. Hierarchical clustering does not fix that number in advance. It returns a tree, a dendrogram, from which every partition from one cluster up to one cluster per point can be read. One may cluster the observations, or transpose the table and cluster the features. The target of K-means is a small within-cluster variation. If are the index sets, they cover and they do not overlap, and the fit minimises for a within-cluster measure .[2]
K-means alternates two steps from an initial guess at the centres. Each point is given to the nearest centre. Each centre is then replaced by the coordinate-wise average of the points just given to it. The steps repeat until the assignment stops changing. The procedure examines a tiny fraction of the partitions and stops at a local minimum of the criterion.[1]
Single linkage, one hierarchical rule, measures the distance between two groups by the minimum of the pairwise distances. Complete linkage uses the maximum. The only change between those two rules is that minimum.[3]
Interpretation
Use a partition when the number of groups is part of the question: market segments, a small number of unknown subtypes, a compression of a sample into centres. Use a hierarchy when the question is which groups nest inside which, and when cutting the tree at several heights is useful. The marketing table with income, occupation, and distance to a city, and no record of who buys the product, is the usual setting: the groups are a proposal about the customers, not a forecast of a purchase.[2]
The distance is not a detail to be left at the default. Standardising a feature that was recorded in tiny units, or leaving it raw, changes which points look close. Subject-matter reasons for the distance play the role that a loss plays in a prediction problem.[1]
For the four points above, the Euclidean distances include , and . Single linkage therefore joins with at distance , joins with at distance , and joins the two pairs at distance , the minimum of the cross distances. With those same pairs treated as K-means clusters, the centre of is and the within-cluster sum of squares is . The centre of is and the within-cluster sum of squares is . The total is . That number is the K-means criterion for this one partition. Another partition can have a smaller value, and a run of the algorithm from a different start can find it.[3] [1]
The colours on a cluster plot are the output of the algorithm. They are not labels that were hidden in the file. In a picture of three groups, two of the groups can overlap, and the word segmentation is the more honest description of what the cut achieved. A smaller within-cluster sum of squares at a larger does not mean that the larger is the right description. More centres can sit closer to the points even when the extra centre has split a single cloud. Cross-validation of a prediction error does not choose , because there is no response to predict.[1] [2]
The methods assume a distance that represents the similarity one cares about. If that distance is wrong, a clean partition is a clean answer to the wrong question. Hierarchical clustering will draw a tree whether or not the points have a nested structure. Single linkage, because it uses the nearest pair, can chain together points that are only neighbours of neighbours. Complete linkage refuses that chain and can refuse an elongated group whose ends are far apart. There is no direct analogue of a test-set error. Agreement with a label that was never shown to the algorithm is a later check, not the criterion that was minimised.[3] [1]
Principal component directions are a different reduction of the same table. They look for a few directions of large variation. Clustering looks for homogeneous subgroups. A plot of the first two component scores is often where a clustering is inspected, and it is not itself the clustering.[2]
Worked example
The six Euclidean distances among , , and that matter for the first joins are , , and . The other cross distances are , and , all larger than . Single linkage joins to at distance and to at distance . The distance from to is the minimum of the four cross distances, the distance .
For the squared Euclidean criterion, the centre of is . The two squared distances to it are each, and they sum to . The centre of is . Each point contributes , and the pair sums to . The partition therefore has within-cluster sum of squares .
Your turn. Three other points are , and . Single linkage joins the first two at distance . What is the single-linkage distance from that pair to ?
The cross distances are and . Single linkage uses the smaller one, so the distance is .
Connections
The two algorithms to read next are hierarchical clustering and Lloyd’s K-means algorithm, together with the K-means criterion. Cluster analysis is the grouping part of unsupervised learning. It is not classification: classification predicts a label that was observed on the training cases. A principal component plot is a map on which clusters are often drawn, and the map optimises variance rather than a within-cluster sum of squares.[2] [1]
Check yourself
Try these questions before opening an answer.
Two starts
Why can two runs of K-means on the same points return different within-cluster sums of squares?
The alternating assignment of points to centres stops at a local minimum. A different start can reach a different partition.
Choosing K
Why is cross-validation of a prediction error not a way to choose the number of clusters?
There is no response to predict, so there is no prediction error to cross-validate. A smaller within-cluster sum of squares at a larger number of centres can just mean the extra centre split one cloud.
Single linkage
Single linkage and complete linkage use the same pairwise distances. What is the only change between them?
Single linkage takes the minimum pairwise distance between groups. Complete linkage takes the maximum.
History
Grouping similar objects runs from ancient typologies through Adanson in the eighteenth century to the clustering methods of Zubin, Tryon, and Thorndike, and the later growth of those methods follows the computer. Single linkage and complete linkage are the hierarchical rules written as updates to a distance table: the distance between classes is the minimum pairwise distance, or the maximum.[3]
The modern statistical development puts the same split, partition versus hierarchy, under unsupervised learning, with K-means as the alternating assignment of points to centres. The search is local. A second start can return a criterion value different from the of one partition of the four points above.[1] [2]
See also
Line chart · Apriori algorithm · Asymptotic analysis · Average treatment effect · Base rate · Bayesian inference · Bayesian model · Bayesian probability
References
- ^ a b c d e f g h i j a. (p. 501) b. (p. 501) c. (p. 501) d. (p. 460, §13.2.1; p. 509) e. (p. 501) f. (p. 460, §13.2.1) g. (pp. 501, 509) h. (p. 509) i. (pp. 501, 509) j. (pp. 460, 501, 509) Hastie, T., Tibshirani, R. & Friedman, J. (2009). The Elements of Statistical Learning. Springer. https://doi.org/10.1007/978-0-387-84858-7
- ^ a b c d e f g h i a. (Ch. 12, p. 495) b. (Ch. 2, §2.1.4) c. (Ch. 2, §2.1.4) d. (Ch. 12, p. 495) e. (Ch. 2, §2.1.4; Ch. 12, p. 495) f. (Ch. 12, p. 495) g. (Ch. 12, p. 495) h. (Ch. 12, p. 495; Ch. 2, §2.1.4) i. (Ch. 12, p. 495) James, G., Witten, D., Hastie, T. & Tibshirani, R. (2021). An Introduction to Statistical Learning: with Applications in R (2nd ed.). Springer, New York. https://doi.org/10.1007/978-1-0716-1418-1
- ^ a b c d e f a. (pp. 83–84) b. (p. 83) c. (pp. 84–85) d. (pp. 84–85) e. (pp. 84–85) f. (pp. 82–85) Dodge, Yadolah (2008). The Concise Encyclopedia of Statistics. Springer. https://doi.org/10.1007/978-0-387-32833-1
Cite this page
StatWiki (2026). "Cluster analysis." StatWiki. Last updated 2 December 2026. https://www.statwiki.io/articles/cluster-analysis.html
@misc{statwiki_cluster_analysis,
author = {{StatWiki}},
title = {{Cluster analysis}},
year = {2026},
url = {https://www.statwiki.io/articles/cluster-analysis.html},
urldate = {2026-12-02},
note = {StatWiki, last updated 2 December 2026}
}