Hierarchical clustering explained

In data mining and statistics, hierarchical clustering (also called hierarchical cluster analysis or HCA) is a method of cluster analysis that seeks to build a hierarchy of clusters. Strategies for hierarchical clustering generally fall into two categories:

In general, the merges and splits are determined in a greedy manner. The results of hierarchical clustering[1] are usually presented in a dendrogram.

Hierarchical clustering has the distinct advantage that any valid measure of distance can be used. In fact, the observations themselves are not required: all that is used is a matrix of distances. On the other hand, except for the special case of single-linkage distance, none of the algorithms (except exhaustive search in

l{O}(2n)

) can be guaranteed to find the optimum solution.

Complexity

The standard algorithm for hierarchical agglomerative clustering (HAC) has a time complexity of

l{O}(n3)

and requires

\Omega(n2)

memory, which makes it too slow for even medium data sets. However, for some special cases, optimal efficient agglomerative methods (of complexity

l{O}(n2)

) are known: SLINK[2] for single-linkage and CLINK[3] for complete-linkage clustering. With a heap, the runtime of the general case can be reduced to

l{O}(n2logn)

, an improvement on the aforementioned bound of

l{O}(n3)

, at the cost of further increasing the memory requirements. In many cases, the memory overheads of this approach are too large to make it practically usable. Methods exist which use quadtrees that demonstrate

l{O}(n2)

total running time with

l{O}(n)

space.[4]

Divisive clustering with an exhaustive search is

l{O}(2n)

, but it is common to use faster heuristics to choose splits, such as k-means.

Cluster Linkage

In order to decide which clusters should be combined (for agglomerative), or where a cluster should be split (for divisive), a measure of dissimilarity between sets of observations is required. In most methods of hierarchical clustering, this is achieved by use of an appropriate distance d, such as the Euclidean distance, between single observations of the data set, and a linkage criterion, which specifies the dissimilarity of sets as a function of the pairwise distances of observations in the sets. The choice of metric as well as linkage can have a major impact on the result of the clustering, where the lower level metric determines which objects are most similar, whereas the linkage criterion influences the shape of the clusters. For example, complete-linkage tends to produce more spherical clusters than single-linkage.

The linkage criterion determines the distance between sets of observations as a function of the pairwise distances between observations.

Some commonly used linkage criteria between two sets of observations A and B and a distance d are:[5] [6]

NamesFormula
Maximum or complete-linkage clustering

maxa\ind(a,b)

Minimum or single-linkage clustering

mina\ind(a,b)

Unweighted average linkage clustering (or UPGMA)
1
|A||B|

\suma\sumd(a,b).

Weighted average linkage clustering (or WPGMA)

d(i\cupj,k)=

d(i,k)+d(j,k)
2

.

Centroid linkage clustering, or UPGMC

\lVert\muA-\mu

2
B\rVert
where

\muA

and

\muB

are the centroids of A resp. B.
Median linkage clustering, or WPGMC

d(i\cupj,k)=d(mi\cup,mk)

where

mi\cup=\tfrac{1}{2}\left(mi+mj\right)

Versatile linkage clustering[7]
\sqrt[p]{1
|A||B|

\suma\sumd(a,b)p},p0

Ward linkage,[8] Minimum Increase of Sum of Squares (MISSQ)
|A||B|
|A\cupB|

\lVert\muA-\muB\rVert2 =\sumx\in\lVertx-\muA\cup\rVert2 -\sumx\in\lVertx-\muA\rVert2 -\sumx\in\lVertx-\muB\rVert2

Minimum Error Sum of Squares (MNSSQ)

\sumx\in\lVertx-\muA\cup\rVert2

Minimum Increase in Variance (MIVAR)
1
|A\cupB|

\sumx\in\lVertx-\muA\cup\rVert2 -

1
|A|

\sumx\in\lVertx-\muA\rVert2 -

1
|B|

\sumx\in\lVertx-\muB\rVert2

=Var(A\cupB)-Var(A)-Var(B)

Minimum Variance (MNVAR)
1
|A\cupB|

\sumx\in\lVertx-\muA\cup\rVert2=Var(A\cupB)

Hausdorff linkage[9]

maxx\inminy\ind(x,y)

Minimum Sum Medoid linkage[10]

minm\in\sumy\ind(m,y)

such that m is the medoid of the resulting cluster
Minimum Sum Increase Medoid linkage

minm\in\sumy\ind(m,y) -minm\in\sumy\ind(m,y) -minm\in\sumy\ind(m,y)

Medoid linkage[11] [12]

d(mA,mB)

where

mA

,

mB

are the medoids of the previous clusters
Minimum energy clustering
2
nm
n,m
\sum
i,j=1

\

a_i- b_j\_2 - \frac \sum_^ \a_i-a_j\_2 - \frac\sum_^ \b_i-b_j\_2
Some of these can only be recomputed recursively (WPGMA, WPGMC), for many a recursive computation with Lance-Williams-equations is more efficient, while for other (Hausdorff, Medoid) the distances have to be computed with the slower full formula. Other linkage criteria include:

Agglomerative clustering example

For example, suppose this data is to be clustered, and the Euclidean distance is the distance metric.

The hierarchical clustering dendrogram would be:

Cutting the tree at a given height will give a partitioning clustering at a selected precision. In this example, cutting after the second row (from the top) of the dendrogram will yield clusters . Cutting after the third row will yield clusters, which is a coarser clustering, with a smaller number but larger clusters.

This method builds the hierarchy from the individual elements by progressively merging clusters. In our example, we have six elements and . The first step is to determine which elements to merge in a cluster. Usually, we want to take the two closest elements, according to the chosen distance.

Optionally, one can also construct a distance matrix at this stage, where the number in the i-th row j-th column is the distance between the i-th and j-th elements. Then, as clustering progresses, rows and columns are merged as the clusters are merged and the distances updated. This is a common way to implement this type of clustering, and has the benefit of caching distances between clusters. A simple agglomerative clustering algorithm is described in the single-linkage clustering page; it can easily be adapted to different types of linkage (see below).

Suppose we have merged the two closest elements b and c, we now have the following clusters,,, and, and want to merge them further. To do that, we need to take the distance between and, and therefore define the distance between two clusters.Usually the distance between two clusters

l{A}

and

l{B}

is one of the following:

max\{d(x,y):x\inl{A},y\inl{B}\}.

min\{d(x,y):x\inl{A},y\inl{B}\}.

{1\over{|l{A}| ⋅ |l{B}|}}\sumx

}\sum_ d(x,y).

In case of tied minimum distances, a pair is randomly chosen, thus being able to generate several structurally different dendrograms. Alternatively, all tied pairs may be joined at the same time, generating a unique dendrogram.[17]

One can always decide to stop clustering when there is a sufficiently small number of clusters (number criterion). Some linkages may also guarantee that agglomeration occurs at a greater distance between clusters than the previous agglomeration, and then one can stop clustering when the clusters are too far apart to be merged (distance criterion). However, this is not the case of, e.g., the centroid linkage where the so-called reversals[18] (inversions, departures from ultrametricity) may occur.

Divisive clustering

The basic principle of divisive clustering was published as the DIANA (DIvisive ANAlysis clustering) algorithm.[19] Initially, all data is in the same cluster, and the largest cluster is split until every object is separate.Because there exist

O(2n)

ways of splitting each cluster, heuristics are needed. DIANA chooses the object with the maximum average dissimilarity and then moves all objects to this cluster that are more similar to the new cluster than to the remainder.

Informally, DIANA is not so much a process of "dividing" as it is of "hollowing out": each iteration, an existing cluster (e.g. the initial cluster of the entire dataset) is chosen to form a new cluster inside of it. Objects progressively move to this nested cluster, and hollow out the existing cluster. Eventually, all that's left inside a cluster is nested clusters that grew there, without it owning any loose objects by itself.

Formally, DIANA operates in the following steps:

  1. Let

C0=\{1...n\}

be the set of all

n

object indices and

l{C}=\{C0\}

the set of all formed clusters so far.
  1. Iterate the following until

|l{C}|=n

:
    1. Find the current cluster with 2 or more objects that has the largest diameter:

C*=\argmaxC\in

} \max_ \delta(i_1,i_2)
    1. Find the object in this cluster with the most dissimilarity to the rest of the cluster:

i*=

\argmax
i\inC*
1
|C*|-1
\sum
j\inC*\setminus\{i\
} \delta(i,j)
    1. Pop

i*

from its old cluster

C*

and put it into a new splinter group

Crm{new}=\{i*\}

.
    1. As long as

C*

isn't empty, keep migrating objects from

C*

to add them to

Crm{new}

. To choose which objects to migrate, don't just consider dissimilarity to

C*

, but also adjust for dissimilarity to the splinter group: let

i*=\argmaxi\inD(i)

where we define

D(i)=

1
|C*|-1
\sum
j\inC*\setminus\{i\
} \delta(i,j) - \frac
\sum_ \delta(i,j), then either stop iterating when

D(i*)<0

, or migrate

i*

.
    1. Add

Crm{new}

to

l{C}

.

Intuitively,

D(i)

above measures how strongly an object wants to leave its current cluster, but it is attenuated when the object wouldn't fit in the splinter group either. Such objects will likely start their own splinter group eventually.

The dendrogram of DIANA can be constructed by letting the splinter group

Crm{new}

be a child of the hollowed-out cluster

C*

each time. This constructs a tree with

C0

as its root and

n

unique single-object clusters as its leaves.

Software

Open source implementations

Commercial implementations

See also

Further reading

Notes and References

  1. Book: Nielsen, Frank . Introduction to HPC with MPI for Data Science . 2016 . Springer . 978-3-319-21903-5 . 195–211. 8. Hierarchical Clustering . https://www.researchgate.net/publication/314700681 .
  2. R. Sibson . SLINK: an optimally efficient algorithm for the single-link cluster method . The Computer Journal . 16 . 1 . 30–34 . 1973 . British Computer Society . 10.1093/comjnl/16.1.30. free .
  3. D. Defays . An efficient algorithm for a complete-link method . The Computer Journal . 20 . 4 . 364–6 . 1977 . British Computer Society . 10.1093/comjnl/20.4.364.
  4. Eppstein . David . 2001-12-31 . Fast hierarchical clustering and other applications of dynamic closest pairs . ACM Journal of Experimental Algorithmics . 5 . 1–es . 10.1145/351827.351829 . 1084-6654. cs/9912014 .
  5. Web site: The CLUSTER Procedure: Clustering Methods . SAS/STAT 9.2 Users Guide . . 2009-04-26.
  6. Székely . G. J. . Rizzo . M. L. . 2005 . Hierarchical clustering via Joint Between-Within Distances: Extending Ward's Minimum Variance Method . Journal of Classification . 22 . 2 . 151–183 . 10.1007/s00357-005-0012-9 . 206960007 .
  7. 10.1007/s00357-019-09339-z . Fernández . Alberto . Gómez . Sergio . Versatile linkage: a family of space-conserving strategies for agglomerative hierarchical clustering . Journal of Classification . 37 . 2020 . 3 . 584–597. 1906.09222 . 195317052 .
  8. Ward . Joe H. . 1963 . Hierarchical Grouping to Optimize an Objective Function . Journal of the American Statistical Association . 58 . 301 . 236–244 . 10.2307/2282967 . 2282967 . 0148188.
  9. Basalto . Nicolas . Bellotti . Roberto . De Carlo . Francesco . Facchi . Paolo . Pantaleo . Ester . Pascazio . Saverio . 2007-06-15 . Hausdorff clustering of financial time series . Physica A: Statistical Mechanics and Its Applications . en . 379 . 2 . 635–644 . 10.1016/j.physa.2007.01.011 . physics/0504014 . 2007PhyA..379..635B . 27093582 . 0378-4371.
  10. Schubert . Erich . 2021 . HACAM: Hierarchical Agglomerative Clustering Around Medoids – and its Limitations . LWDA’21: Lernen, Wissen, Daten, Analysen September 01–03, 2021, Munich, Germany . 191–204 . CEUR-WS.
  11. Miyamoto . Sadaaki . Kaizu . Yousuke . Endo . Yasunori . 2016 . Hierarchical and Non-Hierarchical Medoid Clustering Using Asymmetric Similarity Measures . 2016 Joint 8th International Conference on Soft Computing and Intelligent Systems (SCIS) and 17th International Symposium on Advanced Intelligent Systems (ISIS) . 400–403 . 10.1109/SCIS-ISIS.2016.0091.
  12. 2016 . Visual Clutter Reduction through Hierarchy-based Projection of High-dimensional Labeled Data. Graphics Interface . Dominik. Herr. Qi. Han. Steffen. Lohmann. Thomas . Ertl . 2022-11-04 . Graphics Interface . en-CA . 10.20380/gi2016.14.
  13. Book: Zhang. Wei. Wang. Xiaogang. Zhao. Deli. Tang. Xiaoou. Computer Vision – ECCV 2012 . Graph Degree Linkage: Agglomerative Clustering on a Directed Graph . 2012. Fitzgibbon. Andrew. Lazebnik. Svetlana. Svetlana Lazebnik . Perona. Pietro. Sato. Yoichi. Schmid. Cordelia. Lecture Notes in Computer Science. en. Springer Berlin Heidelberg. 7572. 428–441. 10.1007/978-3-642-33718-5_31. 9783642337185. 1208.5092. 2012arXiv1208.5092Z. 14751. See also: https://github.com/waynezhanghk/gacluster
  14. W. . Zhang . D. . Zhao . X. . Wang . Agglomerative clustering via maximum incremental path integral . Pattern Recognition . 46 . 11 . 3056–65 . 2013 . 10.1016/j.patcog.2013.04.013 . 10.1.1.719.5355 . 2013PatRe..46.3056Z.
  15. Book: Zhao . D. . Tang . X. . Cyclizing clusters via zeta function of a graph . NIPS'08: Proceedings of the 21st International Conference on Neural Information Processing Systems . 2008 . 9781605609492 . 1953–60 . Curran . 10.1.1.945.1649.
  16. Y. . Ma . H. . Derksen . W. . Hong . J. . Wright . Segmentation of Multivariate Mixed Data via Lossy Data Coding and Compression . IEEE Transactions on Pattern Analysis and Machine Intelligence . 29 . 9 . 1546–62 . 2007 . 10.1109/TPAMI.2007.1085 . 17627043 . 2142/99597 . 4591894 . free .
  17. 10.1007/s00357-008-9004-x . Fernández . Alberto . Gómez . Sergio . Solving Non-uniqueness in Agglomerative Hierarchical Clustering Using Multidendrograms . Journal of Classification . 25 . 2008 . 1 . 43–65. cs/0608049 . 434036 .
  18. Book: P. . Legendre . L.F.J. . Legendre . Cluster Analysis §8.6 Reversals . Numerical Ecology . https://books.google.com/books?id=DKlUIQcHhOsC&pg=PA376 . 2012 . Elsevier . 978-0-444-53868-0 . 376–7 . 3rd . Developments in Environmental Modelling . 24.
  19. Book: L. . Kaufman . P.J. . Rousseeuw . 6. Divisive Analysis (Program DIANA) . Finding Groups in Data: An Introduction to Cluster Analysis . https://books.google.com/books?id=YeFQHiikNo0C&pg=PA253 . 1990 . 2009 . Wiley . 978-0-470-31748-8 . 253–279.
  20. Web site: Hierarchical Clustering · Clustering.jl . 2022-02-28 . juliastats.org . en.
  21. Web site: hclust function - RDocumentation . 2022-06-07 . www.rdocumentation.org . en.
  22. Web site: Paradis. Emmanuel. etal . ape: Analyses of Phylogenetics and Evolution. 2022-12-28.
  23. Web site: Fernández. Alberto. Gómez. Sergio. 2021-09-12. mdendro: Extended Agglomerative Hierarchical Clustering. 2022-12-28.