- Introduced by
- Robert C. Tryon (early development); Ward (1963) for hierarchical; MacQueen (1967) for k-means
- Year
- 1939–1967
- Type
- Unsupervised classification / grouping
- Family
- Multivariate analysis
What does it do?
Cluster analysis is a family of unsupervised multivariate techniques that partition objects or observations into groups, called clusters, whose members are similar to one another on measured characteristics and distinct from members of other clusters.
No outcome variable is specified, so group membership is inferred from the data rather than known in advance. It is used in fields such as market research, bioinformatics, psychology and the social sciences to explore whether natural groupings exist.
The intuition behind the method
Imagine a set of data points scattered in space. Observations that lie close together should belong to the same group, and observations that lie far apart should belong to different groups. Cluster analysis turns this geometric idea into a formal procedure: it defines a measure of similarity or distance between observations and then groups them so that variation within clusters is small relative to variation between clusters. No outcome variable guides the grouping, so any structure that appears emerges from the data, and whether that structure is meaningful is a separate question for the analyst.
History
Cluster analysis is best understood as a family of techniques rather than a single method. Cleff (2019, p. 408) notes that many clustering methods exist, with a wide variety of distance measures and linkage algorithms, and identifies two general types: hierarchical cluster analysis, which builds a nested sequence of merges, and k-means cluster analysis, which iteratively reassigns observations to a fixed number of groups. The methods described on this page belong to these two families.
When to use it
Choose cluster analysis when the aim is to discover groups in data without a predefined outcome, for example market segments, patient subgroups, species types or respondent profiles. Used descriptively, cluster analysis requires few formal assumptions, because inferences about the clusters are usually not performed (Denis, section 13.9). Even so, observations should be separate cases, and the variables should be measured consistently across them. Standardise continuous variables when they are on different scales, and be aware that multicollinearity among the variables may be a concern. Do not use cluster analysis when group membership is already known and the goal is to assign new cases to those groups; discriminant analysis is the appropriate tool for that, because it rests on a prior theory of group membership (Denis, section 13.9). When the number of variables is large relative to the number of observations, distances can become unstable, and dimensionality reduction such as principal component analysis may be needed first. Because every algorithm returns groups, the chosen solution should be validated on new data or with a split-sample check before substantive conclusions are drawn.
Limitations and considerations
- The method does not fix the number of clusters: k-means requires it to be specified, and for hierarchical methods the cut height is a judgement, so the result depends on the analyst's choice.
- Solutions depend on the proximity measure, the linkage criterion and, for k-means, the starting configuration; changing any of these can change the groups.
- Partitioning algorithms return groups even when the data contain no real structure, so a clustering result is not evidence of clusters by itself.
- Methods built on means or centroids are sensitive to outliers, since a few extreme observations can pull a centroid away from the bulk of its members.
- The partitions described here are hard: boundary observations are assigned to one group even when their membership is ambiguous.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Data-driven: it searches for groups without imposing a grouping theory, so it can suggest structure that was not hypothesised in advance.
- Flexible with data type: the choice of proximity measure (Euclidean, Gower, Jaccard or matching coefficients) determines whether continuous, ordinal, binary or mixed variables can be handled.
- Hierarchical methods show the full nested structure in the dendrogram, so the analyst can compare solutions with different numbers of clusters before fixing k.
- k-means is efficient for large datasets when k is roughly known.
- It can be applied to factor scores or principal components when the original variables are numerous or highly correlated.
Applications
- Market segmentation: grouping consumers by purchasing behaviour, attitudes, or demographics to tailor marketing strategies.
- Bioinformatics: identifying gene expression profiles or grouping patients by molecular subtypes for precision medicine.
- Psychology and education: discovering latent respondent profiles or learner types in survey and test data.
- Social science: classifying countries, organisations, or communities by structural characteristics to support comparative research.
- Image analysis and pattern recognition: segmenting pixels or features into coherent regions.
- Anomaly detection: identifying observations that do not belong to any well-defined cluster as potential outliers or novel cases.
How it works
How it works
The first step is choosing a proximity measure, and the choice matters because many distance measures and linkage algorithms are available (Cleff, 2019, p. 408). For continuous variables, the Euclidean distance given in the distance step is the usual starting point, and it places observations that are similar on all measured variables close together. Euclidean distance is not suitable for purely categorical data: binary variables call for Jaccard or simple matching coefficients, and mixed variable types can be handled with Gower's coefficient. If variables differ substantially in scale, they should be standardised before distances are computed, so that high-variance variables do not dominate the grouping. The k-means assignment step below works with squared distances.
Formula
d(\mathbf{x}_i, \mathbf{x}_j) = \sqrt{\sum_{k=1}^{p}(x_{ik}-x_{jk})^2}In hierarchical clustering, observations or clusters are merged step by step. The linkage criterion defines the distance between two emerging clusters: single linkage uses the closest pair of members, complete linkage uses the most distant pair, average linkage uses the mean distance over all pairs, and Ward's method merges the two clusters that give the smallest increase in total within-cluster sum of squares. Ward's criterion tends to produce compact clusters. Once two observations or clusters are fused, they typically remain together in later steps (Denis, section 13.9). The sequence of merges is shown as a dendrogram, and the analyst chooses a cut height that gives an interpretable number of clusters.
In partitional clustering, with k-means as the canonical example, the analyst specifies the number of clusters k in advance. Each observation is assigned to the cluster whose centroid, the mean vector of its current members, is nearest in Euclidean distance. The centroid serves as the representative profile of its cluster.
Formula
C(\mathbf{x}_i) = \arg\min_{k} \|\mathbf{x}_i - \boldsymbol{\mu}_k\|^2After the initial assignment, each centroid is recalculated as the mean of the observations currently in its cluster, and observations are reassigned to the nearest updated centroid. The assignment and update steps repeat until no observation changes cluster. This yields a locally optimal partition rather than a guaranteed global optimum. Because the result depends on starting values, the algorithm is normally run many times from different random starts, and the solution with the lowest total within-cluster sum of squares is retained.
Formula
\boldsymbol{\mu}_k = \frac{1}{|C_k|}\sum_{\mathbf{x}_i \in C_k} \mathbf{x}_iNo gold-standard criterion identifies the correct number of clusters, because the true number is unknown. Internal indices compare within-cluster cohesion with between-cluster separation; the silhouette width and the Calinski-Harabasz index are common examples. The elbow method plots total within-cluster sum of squares against k and looks for a bend. For hierarchical solutions, the dendrogram and the sequence of merge heights guide the choice of cut. Any candidate solution should also be judged on substantive grounds: clusters should differ on theoretically relevant variables and should reproduce on a holdout sample or under resampling.
Common pitfalls
- Forgetting to standardise variables before computing Euclidean distances. High-variance variables then dominate the distances, and variables on small scales contribute little.
- Accepting the first solution without comparing alternatives. Different linkage methods, distance measures and values of k can give different partitions, and their stability should be compared.
- Over-interpreting trivial clusters. Partitioning algorithms return k groups whether or not real structure exists; check internal indices and compare against a baseline, such as permuted data, before interpreting the groups.
- Using k-means where the true clusters are elongated, irregular or of very unequal size. k-means favours roughly spherical clusters of similar size and can split or merge natural groups in such data.
- Testing group differences on the same data used to form the clusters and reporting them as if the groups had been measured in advance. Because the clusters were built from these data, the usual significance tests are not valid without correction or independent data.
Frequently asked questions
How do I decide how many clusters to use?
No single rule settles this. Common aids include the elbow method (plot total within-cluster sum of squares against k and look for a clear bend), the silhouette width (a higher average silhouette indicates better-separated clusters) and the Calinski-Harabasz index. For hierarchical solutions, inspect the dendrogram and the merge heights for large jumps. The chosen number should also make substantive sense and remain stable when the analysis is repeated.
What is the difference between hierarchical and k-means clustering?
Hierarchical clustering builds a nested sequence of groupings by merging (agglomerative) or splitting (divisive) observations, and the analyst decides where to cut the tree. K-means requires k to be specified in advance and then iteratively assigns each observation to its nearest centroid. Hierarchical methods are useful for exploring the full range of groupings and are often used with smaller samples; k-means is more efficient for large datasets when k is roughly known.
Should I standardise my variables before clustering?
Yes, when variables are measured on different scales. Without standardisation, variables with large numeric ranges dominate Euclidean distances. Z-score standardisation (subtracting the mean and dividing by the standard deviation) is a common choice; rescaling to a 0 to 1 range is an alternative when the original scale is meaningful.
Can cluster analysis handle categorical variables?
Standard Euclidean distance is not suitable for purely categorical variables. Gower's distance can combine mixed data types, and Jaccard or simple matching coefficients suit binary data. Converting categories to dummy codes is possible, but the resulting clusters should be interpreted cautiously. Latent class analysis is a model-based alternative designed for categorical indicators.
How do I validate a cluster solution?
Internal validation compares within-cluster cohesion and between-cluster separation, for example with silhouette width. External validation checks whether the clusters correspond to criteria not used in forming them, such as known group membership in a holdout sample. Stability is assessed by repeating the analysis on bootstrap resamples or random splits and checking how consistently observations are grouped together.
Related methods
Sources
Everitt, B. S., Landau, S., Leese, M. & Stahl, D. (2011). Cluster Analysis (5th ed.). Wiley.
ISBN: 978-0470749913Hair, J. F., Black, W. C., Babin, B. J. & Anderson, R. E. (2019). Multivariate Data Analysis (8th ed.). Cengage Learning.
ISBN: 978-1473756540Applied Statistics and Multivariate Data Analysis for Business and Economics: A Modern Approach Using SPSS, Stata, and Excel (2019), p. 408
Denis, D. J., SPSS Data Analysis for Univariat[e] (library copy), section 13.9 Cluster Analysis