Understand the idea
Instead of deciding up front how many groups you want, this method builds the WHOLE family tree of groupings: it starts with every observation as its own tiny cluster, then repeatedly merges whichever two clusters are currently closest, all the way up until everything is one giant cluster. The result is a dendrogram: a branching diagram where the height of each merge shows how far apart the two things being joined were.
You can then 'cut' this tree at any height to get a flat set of groups: cut low and you get many small, tight clusters; cut high and you get a few big, loose ones. A common way to pick where to cut is to look for a big vertical gap in the dendrogram (a stretch where nothing merges for a while), which suggests a natural break in the structure.
The 'linkage' choice decides what 'distance between two clusters' even means once each cluster has more than one point in it: the closest pair of points between them (single), the farthest pair (complete), the average over all pairs, or Ward's method, which merges whichever pair increases within-cluster spread the least. Different linkage choices can produce genuinely different-looking trees from the exact same data, so the choice matters.
Hierarchical clustering of this kind is agglomerative clustering: it starts with every row as its own cluster and repeatedly merges the two closest clusters. Ward linkage, a common choice, merges the pair of clusters that adds the least spread within clusters. The cophenetic correlation measures how faithfully the tree keeps the original distances; closer to 1 is better.
Practitioner explanation
KernelStats standardizes by default (mean 0, SD 1 per variable) before computing pairwise distances, because distances drive every merge and an unscaled high-variance variable would dominate. Ward linkage is offered alongside complete, average, and single, and Ward is FORCED to use Euclidean distance regardless of the metric selected, since Ward's minimum-variance criterion is only mathematically defined for Euclidean distance.
Cophenetic correlation (comparing the tree's implied distances to the original pairwise distances) is computed exactly, but ONLY up to a row ceiling, because it requires the full O(n^2) distance matrix; above 10,000 rows the card reports the silhouette from a random 2,000-row sample instead and states plainly that no cophenetic correlation is available at that size; the CLUSTERING itself always uses every row regardless of this ceiling. A 40,000-row limit is planned because the O(n^2) condensed distance matrix alone needs about 6.4 GB at that scale, before the linkage's working copies, and the card refuses a selection above 40,000 complete rows with a message that names the limit and suggests k-means or a random subsample of at most 40,000 rows; well below that size a large table can still run slowly, so k-means is the better tool for very large data.
The reported cut height is deliberately NOT simply the height of the blocking merge: because a cut at a given height is inclusive (every merge at or below it is made), there is a whole WINDOW of heights that all produce the identical partition, and KernelStats reports a height strictly inside that window so pasting it into scipy's fcluster(criterion='distance') or R's cutree(h=) reproduces the exact same clusters shown on the card. When ties in merge height make no single height give the requested cluster count at all, the card says so honestly rather than printing a height that silently does something else.
When to use it
Consider it when
You want to discover nested groupings in continuous numeric data without committing to a number of clusters up front, and want to inspect the tree structure itself (via the dendrogram) to decide where a natural cut point lies.
Use caution when
Very large datasets (the full distance matrix costs O(n^2) memory, about 6.4 GB for the distance matrix alone at 40,000 rows, so use k-means instead, which scales to the whole table), when you already know exactly how many clusters you want and do not need the tree structure (k-means is simpler and faster), or when clusters are expected to be highly elongated/chain-like with single linkage specifically producing an unhelpfully stringy tree.
Formulas and symbols
Cophenetic correlation
d_ij the original pairwise distance; d-cophenetic_ij the height at which i and j first join the same cluster in the tree. Near 1 means the tree faithfully represents the original distances.
Silhouette score
a the mean distance to points in the same cluster; b the mean distance to the nearest other cluster. Ranges -1 to +1; higher is better-separated.
Assumptions and checks
- Hierarchical clustering's dendrogram depends heavily on the chosen distance metric and linkage method (single, complete, average, Ward); a mismatch between the linkage's implicit cluster shape and the data's actual structure produces a dendrogram that looks decisive but does not reflect genuine groups (e.g. single linkage chains together nearby points even across weak bridges).
In KernelStats: Not checked by KernelStats: no diagnostic compares linkage choices or validates the implied cluster shape against the data; the cophenetic correlation reported measures how well the dendrogram preserves the original distances overall, not whether the chosen linkage suits this particular data's shape.
- Variables on very different scales let the highest-variance variable dominate the distance the clustering minimizes, so the resulting groups reflect scale rather than genuine similarity.
In KernelStats: Handled by default rather than checked: the standardize option (on by default) rescales every variable to mean 0, SD 1 before distances are computed; if the analyst turns it off, the card does not flag variables on very different scales.
- Independence of observations. Hierarchical clustering treats every row as an independent point; clustering rows that are actually repeated measurements of the same unit, or otherwise dependent, can create spurious groups that just reflect the dependency structure rather than genuine subpopulations.
In KernelStats: Not checked by KernelStats.
Alternatives
- k-Means Clustering. The dataset is large (tens of thousands of rows or more) or you already know the target number of clusters and do not need the full dendrogram/tree structure.
- Principal Component Analysis. You want to reduce dimensionality or visualize structure among VARIABLES rather than group OBSERVATIONS into clusters.
Worked example
Scenario
Agglomerative clustering (Ward linkage, Euclidean distance, standardized) on four penguin body measurements across 342 birds, cut into 3 clusters.
Result
Cophenetic correlation = 0.83, silhouette = 0.45; cluster sizes are 123, 57 and 162, so one cluster matches the 123 Gentoo exactly while the other two split the 151 Adelie and 68 Chinstrap imperfectly.
Interpretation
The dendrogram represents the original distances reasonably faithfully, and the 3-cluster cut recovers one species cleanly, but the moderate silhouette and the Adelie/Chinstrap mixing show the body measurements alone do not separate all three species; agreement with a known grouping on one cluster is not proof that three is the right number of clusters.
Dataset: penguins.csv
Common misconceptions
Misconception
Different linkage methods (Ward, complete, average, single) applied to the same data will produce essentially the same tree, just with minor numerical differences.
Correction
Linkage methods define cluster-to-cluster distance in genuinely different ways and can produce qualitatively different trees from identical data: Ward tends toward compact, similarly sized clusters; single linkage can 'chain' elongated groups together in a way the other methods never would. The choice of linkage is a modeling decision with real consequences, not a minor implementation detail.
Misconception
The height printed as the 'cut height' for k clusters is the one exact height where that partition exists; any other nearby height would give a different number of clusters.
Correction
A cut height is INCLUSIVE (every merge at or below it happens), so there is a whole window of heights, from just above the last merge kept to just below the first merge blocked, that all yield the identical partition. The reported height is chosen to sit strictly inside that window for reproducibility, not because it is the unique value that works.
References
- NIST/SEMATECH e-Handbook of Statistical Methods, §8.4 Cluster analysis, NIST/SEMATECH (2012), §8.4.
- Silhouettes: A graphical aid to the interpretation and validation of cluster analysis, Rousseeuw, P. J. (1987), Journal of Computational and Applied Mathematics, 20, 53-65.
