Hierarchical clustering: Difference between revisions
m Undid revision 1256702895 by Babakmd (talk) Refspamming |
|||
(46 intermediate revisions by 27 users not shown) | |||
Line 10: | Line 10: | ||
|chapter=8. Hierarchical Clustering | url=https://www.springer.com/gp/book/9783319219028 |chapter-url=https://www.researchgate.net/publication/314700681 }}</ref> are usually presented in a [[dendrogram]]. |
|chapter=8. Hierarchical Clustering | url=https://www.springer.com/gp/book/9783319219028 |chapter-url=https://www.researchgate.net/publication/314700681 }}</ref> 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 [[distance matrix|matrix of distances]]. On the other hand, except for the special case of single-linkage distance, none of the algorithms (except exhaustive search in <math>\mathcal{O}(2^n)</math>) can be guaranteed to find the optimum solution.{{cn|date=October 2024}} |
|||
The standard algorithm for '''hierarchical agglomerative clustering''' (HAC) has a [[time complexity]] of <math>\mathcal{O}(n^3)</math> and requires <math>\Omega(n^2)</math> memory, which makes it too slow for even medium data sets. However, for some special cases, optimal efficient agglomerative methods (of complexity <math>\mathcal{O}(n^2)</math>) are known: '''SLINK'''<!--boldface per WP:R#PLA--><ref name="SLINK">{{cite journal | author=R. Sibson | title=SLINK: an optimally efficient algorithm for the single-link cluster method | journal=The Computer Journal | volume=16 | issue=1 | pages=30–34 | year=1973 | publisher=British Computer Society | url=http://www.cs.gsu.edu/~wkim/index_files/papers/sibson.pdf | doi=10.1093/comjnl/16.1.30| doi-access=free }}</ref> for [[Single-linkage clustering|single-linkage]] and CLINK<ref name="CLINK">{{cite journal | author=D. Defays | title=An efficient algorithm for a complete-link method | journal=The Computer Journal | volume=20 | issue=4 | pages=364–6 | year=1977 | publisher=British Computer Society | doi=10.1093/comjnl/20.4.364| doi-access=free }}</ref> for [[complete-linkage clustering]]. With a [[heap (data structure)|heap]], the runtime of the general case can be reduced to <math>\mathcal{O}(n^2 \log n)</math>, an improvement on the aforementioned bound of <math>\mathcal{O}(n^3)</math>, 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. |
|||
== Complexity == |
|||
Except for the special case of single-linkage, none of the algorithms (except exhaustive search in <math>\mathcal{O}(2^n)</math>) can be guaranteed to find the optimum solution. |
|||
The standard algorithm for '''hierarchical agglomerative clustering''' (HAC) has a [[time complexity]] of <math>\mathcal{O}(n^3)</math> and requires <math>\Omega(n^2)</math> memory, which makes it too slow for even medium data sets. However, for some special cases, optimal efficient agglomerative methods (of complexity <math>\mathcal{O}(n^2)</math>) are known: '''SLINK'''<!--boldface per WP:R#PLA--><ref name="SLINK">{{cite journal | author=R. Sibson | title=SLINK: an optimally efficient algorithm for the single-link cluster method | journal=The Computer Journal | volume=16 | issue=1 | pages=30–34 | year=1973 | publisher=British Computer Society | url=http://www.cs.gsu.edu/~wkim/index_files/papers/sibson.pdf | doi=10.1093/comjnl/16.1.30| doi-access=free }}</ref> for [[Single-linkage clustering|single-linkage]] and CLINK<ref name="CLINK">{{cite journal | author=D. Defays | title=An efficient algorithm for a complete-link method | journal=The Computer Journal | volume=20 | issue=4 | pages=364–6 | year=1977 | publisher=British Computer Society | doi=10.1093/comjnl/20.4.364| doi-access= }}</ref> for [[complete-linkage clustering]]. With a [[heap (data structure)|heap]], the runtime of the general case can be reduced to <math>\mathcal{O}(n^2 \log n)</math>, an improvement on the aforementioned bound of <math>\mathcal{O}(n^3)</math>, 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 [[quadtree]]s that demonstrate <math>\mathcal{O}(n^2)</math> total running time with <math>\mathcal{O}(n)</math> space.<ref>{{Cite journal |last=Eppstein |first=David |date=2001-12-31 |title=Fast hierarchical clustering and other applications of dynamic closest pairs |url=https://dl.acm.org/doi/10.1145/351827.351829 |journal=ACM Journal of Experimental Algorithmics |volume=5 |pages=1–es |doi=10.1145/351827.351829 |issn=1084-6654|arxiv=cs/9912014 }}</ref> |
|||
Divisive clustering with an exhaustive search is <math>\mathcal{O}(2^n)</math>, but it is common to use faster heuristics to choose splits, such as [[k-means clustering|''k''-means]]. |
Divisive clustering with an exhaustive search is <math>\mathcal{O}(2^n)</math>, but it is common to use faster heuristics to choose splits, such as [[k-means clustering|''k''-means]]. |
||
== Cluster |
== 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 [[ |
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 [[similarity measure|similar]], whereas the linkage criterion influences the shape of the clusters. For example, complete-linkage tends to produce more spherical clusters than single-linkage. |
||
=== Metric === |
|||
{{Further|Metric (mathematics)}} |
|||
The choice of an appropriate metric will influence the shape of the clusters, as some elements may be relatively closer to one another under one metric than another. For example, in two dimensions, under the Manhattan distance metric, the distance between the origin (0,0) and (0.5, 0.5) is the same as the distance between the origin and (0, 1), while under the Euclidean distance metric the latter is strictly greater. |
|||
Some commonly used metrics for hierarchical clustering are:<ref>{{cite web | title=The DISTANCE Procedure: Proximity Measures | url=https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/statug_distance_sect016.htm | work=SAS/STAT 9.2 Users Guide | publisher= [[SAS Institute]] | access-date=2009-04-26}}</ref> |
|||
{|class="wikitable" |
|||
! Names |
|||
! Formula |
|||
|- |
|||
| [[Euclidean distance]] |
|||
| <math> \|a-b \|_2 = \sqrt{\sum_i (a_i-b_i)^2} </math> |
|||
|- |
|||
| [[Squared Euclidean distance]] |
|||
| <math> \|a-b \|_2^2 = \sum_i (a_i-b_i)^2 </math> |
|||
|- |
|||
| [[Manhattan distance|Manhattan (or city block ) distance]] |
|||
| <math> \|a-b \|_1 = \sum_i |a_i-b_i| </math> |
|||
|- |
|||
| [[Uniform norm|Maximum distance (or Chebyshev distance)]] |
|||
| <math> \|a-b \|_\infty = \max_i |a_i-b_i| </math> |
|||
|- |
|||
| [[Mahalanobis distance]] |
|||
| <math> \sqrt{(a-b)^{\top}S^{-1}(a-b)} </math> where ''S'' is the [[Covariance matrix]] |
|||
|- |
|||
|} |
|||
For text or other non-numeric data, metrics such as the [[Hamming distance]] or [[Levenshtein distance]] are often used. |
|||
[[Euclidean distance|Euclidean]] and [[Manhattan distance|Manhattan]] distances are the special cases of generalized [[Minkowski distance]] with p = 1 (for Manhattan) and p = 2 (for Euclidean). |
|||
Several other dissimilarity measures exist. Particularly, correlation-based distances - Pearson, Eisen cosine, Spearman, Kendall correlation distances, which are widely used for gene expression data analyses. Correlation-based distance is defined by subtracting the correlation coefficient from 1. Strictly speaking, correlation-based distances cannot be used as metric, while the square root of it can be.<ref>{{cite arXiv|eprint = 1908.06029|last1 = Solo|first1 = Victor|title = Pearson Distance is not a Distance|year = 2019|class = stat.ME}}</ref> |
|||
A review of cluster analysis in health psychology research found that the most common distance measure in published studies in that research area is the Euclidean distance or the squared Euclidean distance.{{Citation needed|date=April 2009}} |
|||
=== Linkage criteria === |
|||
The linkage criterion determines the distance between sets of observations as a function of the pairwise distances between observations. |
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'' are:<ref>{{cite web | title=The CLUSTER Procedure: Clustering Methods | url=https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/statug_cluster_sect012.htm | work=SAS/STAT 9.2 Users Guide | publisher= [[SAS Institute]] | access-date=2009-04-26}}</ref><ref>{{cite journal |last1=Székely |first1=G. J. |last2=Rizzo |first2=M. L. |year=2005 |title=Hierarchical clustering via Joint Between-Within Distances: Extending Ward's Minimum Variance Method |journal=Journal of Classification |volume=22 |issue=2 |pages=151–183 |doi=10.1007/s00357-005-0012-9 |s2cid=206960007 }}</ref> |
Some commonly used linkage criteria between two sets of observations ''A'' and ''B'' and a distance ''d'' are:<ref>{{cite web | title=The CLUSTER Procedure: Clustering Methods | url=https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/statug_cluster_sect012.htm | work=SAS/STAT 9.2 Users Guide | publisher= [[SAS Institute]] | access-date=2009-04-26}}</ref><ref>{{cite journal |last1=Székely |first1=G. J. |last2=Rizzo |first2=M. L. |year=2005 |title=Hierarchical clustering via Joint Between-Within Distances: Extending Ward's Minimum Variance Method |journal=Journal of Classification |volume=22 |issue=2 |pages=151–183 |doi=10.1007/s00357-005-0012-9 |s2cid=206960007 }}</ref> |
||
{|class="wikitable" |
{|class="wikitable" |
||
! Names |
! Names |
||
Line 62: | Line 28: | ||
|- |
|- |
||
| Maximum or [[complete-linkage clustering]] |
| Maximum or [[complete-linkage clustering]] |
||
| <math> \ |
| <math> \max_{a\in A,\, b\in B} d(a,b) </math> |
||
|- |
|- |
||
| Minimum or [[single-linkage clustering]] |
| Minimum or [[single-linkage clustering]] |
||
| <math> \ |
| <math> \min_{a\in A,\, b\in B} d(a,b) </math> |
||
|- |
|- |
||
| Unweighted average linkage clustering (or [[UPGMA]]) |
| Unweighted average linkage clustering (or [[UPGMA]]) |
||
Line 73: | Line 39: | ||
| <math> d(i \cup j, k) = \frac{d(i, k) + d(j, k)}{2}. </math> |
| <math> d(i \cup j, k) = \frac{d(i, k) + d(j, k)}{2}. </math> |
||
|- |
|- |
||
| Centroid linkage clustering, or |
| Centroid linkage clustering, or UPGMC |
||
| <math> |
| <math>\lVert \mu_A-\mu_B\rVert^2</math> where <math>\mu_A</math> and <math>\mu_B</math> are the centroids of ''A'' resp. ''B''. |
||
|- |
|||
|Median linkage clustering, or WPGMC |
|||
|<math>d(i\cup j, k) = d(m_{i\cup j}, m_k)</math> where <math>m_{i\cup j} = \tfrac{1}{2}\left(m_i + m_j\right)</math> |
|||
|- |
|||
|Versatile linkage clustering<ref>{{cite journal | doi=10.1007/s00357-019-09339-z | last1=Fernández | first1=Alberto | last2=Gómez | first2=Sergio | title=Versatile linkage: a family of space-conserving strategies for agglomerative hierarchical clustering | journal=Journal of Classification | volume=37 | year=2020 | issue=3 | pages=584–597| arxiv=1906.09222 | s2cid=195317052 }}</ref> |
|||
| <math>\sqrt[p]{\frac{1}{|A|\cdot|B|} \sum_{a \in A }\sum_{ b \in B} d(a,b)^p}, p\neq 0</math> |
|||
|- |
|||
|[[Ward's method|Ward linkage]],<ref name="wards method">{{cite journal |last=Ward |first=Joe H. |year=1963 |title=Hierarchical Grouping to Optimize an Objective Function |journal=Journal of the American Statistical Association |volume=58 |issue=301 |pages=236–244 |doi=10.2307/2282967 |jstor=2282967 |mr=0148188}}</ref> Minimum Increase of Sum of Squares (MISSQ)<ref name=":0">{{Citation |last=Podani |first=János |title=New combinatorial clustering methods |date=1989 |url=https://doi.org/10.1007/978-94-009-2432-1_5 |work=Numerical syntaxonomy |pages=61–77 |editor-last=Mucina |editor-first=L. |place=Dordrecht |publisher=Springer Netherlands |language=en |doi=10.1007/978-94-009-2432-1_5 |isbn=978-94-009-2432-1 |access-date=2022-11-04 |editor2-last=Dale |editor2-first=M. B.}}</ref> |
|||
|<math>\frac{|A|\cdot|B|}{|A\cup B|} \lVert \mu_A - \mu_B \rVert ^2 |
|||
= \sum_{x\in A\cup B} \lVert x - \mu_{A\cup B} \rVert^2 |
|||
- \sum_{x\in A} \lVert x - \mu_{A} \rVert^2 |
|||
- \sum_{x\in B} \lVert x - \mu_{B} \rVert^2</math> |
|||
|- |
|||
|Minimum Error Sum of Squares (MNSSQ)<ref name=":0" /> |
|||
|<math>\sum_{x\in A\cup B} \lVert x - \mu_{A\cup B} \rVert^2</math> |
|||
|- |
|||
|Minimum Increase in Variance (MIVAR)<ref name=":0" /> |
|||
|<math>\frac{1}{|A\cup B|}\sum_{x\in A\cup B} \lVert x - \mu_{A\cup B} \rVert^2 |
|||
- \frac{1}{|A|}\sum_{x\in A} \lVert x - \mu_{A} \rVert^2 |
|||
- \frac{1}{|B|}\sum_{x\in B} \lVert x - \mu_{B} \rVert^2</math><math>= \text{Var}(A\cup B) - \text{Var}(A) - \text{Var}(B)</math> |
|||
|- |
|||
|Minimum Variance (MNVAR)<ref name=":0" /> |
|||
|<math>\frac{1}{|A\cup B|}\sum_{x\in A\cup B} \lVert x - \mu_{A\cup B} \rVert^2 = \text{Var}(A\cup B)</math> |
|||
|- |
|||
|Hausdorff linkage<ref>{{Cite journal |last1=Basalto |first1=Nicolas |last2=Bellotti |first2=Roberto |last3=De Carlo |first3=Francesco |last4=Facchi |first4=Paolo |last5=Pantaleo |first5=Ester |last6=Pascazio |first6=Saverio |date=2007-06-15 |title=Hausdorff clustering of financial time series |url=https://www.sciencedirect.com/science/article/pii/S0378437107001124 |journal=Physica A: Statistical Mechanics and Its Applications |language=en |volume=379 |issue=2 |pages=635–644 |doi=10.1016/j.physa.2007.01.011 |arxiv=physics/0504014 |bibcode=2007PhyA..379..635B |s2cid=27093582 |issn=0378-4371}}</ref> |
|||
|<math>\max_{x\in A\cup B} \min_{y\in A\cup B} d(x,y)</math> |
|||
|- |
|||
|Minimum Sum Medoid linkage<ref name=":1">{{Cite conference |last=Schubert |first=Erich |date=2021 |title=HACAM: Hierarchical Agglomerative Clustering Around Medoids – and its Limitations |url=http://star.informatik.rwth-aachen.de/Publications/CEUR-WS/Vol-2993/paper-19.pdf |conference=LWDA’21: Lernen, Wissen, Daten, Analysen September 01–03, 2021, Munich, Germany |pages=191–204 |via=CEUR-WS}}</ref> |
|||
|<math>\min_{m\in A\cup B} \sum_{y\in A\cup B} d(m, y)</math> such that m is the medoid of the resulting cluster |
|||
|- |
|||
|Minimum Sum Increase Medoid linkage<ref name=":1" /> |
|||
|<math>\min_{m\in A\cup B} \sum_{y\in A\cup B} d(m,y) |
|||
- \min_{m\in A} \sum_{y\in A} d(m,y) |
|||
- \min_{m\in B} \sum_{y\in B} d(m,y)</math> |
|||
|- |
|||
|Medoid linkage<ref>{{Cite conference |last1=Miyamoto |first1=Sadaaki |last2=Kaizu |first2=Yousuke |last3=Endo |first3=Yasunori |date=2016 |title=Hierarchical and Non-Hierarchical Medoid Clustering Using Asymmetric Similarity Measures |url=https://ieeexplore.ieee.org/document/7801678 |conference=2016 Joint 8th International Conference on Soft Computing and Intelligent Systems (SCIS) and 17th International Symposium on Advanced Intelligent Systems (ISIS) |pages=400–403 |doi=10.1109/SCIS-ISIS.2016.0091}}</ref><ref>{{Cite conference |date=2016 |title=Visual Clutter Reduction through Hierarchy-based Projection of High-dimensional Labeled Data| conference=Graphics Interface |url=https://graphicsinterface.org/wp-content/uploads/gi2016-14.pdf | first1=Dominik|last1=Herr|first2=Qi|last2=Han|first3=Steffen|last3=Lohmann| first4=Thomas |last4=Ertl |access-date=2022-11-04 |website=Graphics Interface |language=en-CA |doi=10.20380/gi2016.14}}</ref> |
|||
|<math>d(m_A, m_B)</math> where <math>m_A</math>, <math>m_B</math> are the medoids of the previous clusters |
|||
|- |
|- |
||
| [[Energy distance|Minimum energy clustering]] |
| [[Energy distance|Minimum energy clustering]] |
||
| <math> \frac {2}{nm}\sum_{i,j=1}^{n,m} \|a_i- b_j\|_2 - \frac {1}{n^2}\sum_{i,j=1}^{n} \|a_i-a_j\|_2 - \frac{1}{m^2}\sum_{i,j=1}^{m} \|b_i-b_j\|_2 </math> |
| <math> \frac {2}{nm}\sum_{i,j=1}^{n,m} \|a_i- b_j\|_2 - \frac {1}{n^2}\sum_{i,j=1}^{n} \|a_i-a_j\|_2 - \frac{1}{m^2}\sum_{i,j=1}^{m} \|b_i-b_j\|_2 </math> |
||
|} |
|} |
||
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: |
|||
where ''d'' is the chosen metric. Other linkage criteria include: |
|||
* The sum of all intra-cluster variance. |
|||
* The increase in variance for the cluster being merged ([[Ward's method|Ward's criterion]]).<ref name="wards method">{{cite journal |
|||
|doi=10.2307/2282967 |
|||
|last=Ward |first=Joe H. |
|||
|title=Hierarchical Grouping to Optimize an Objective Function |
|||
|journal=Journal of the American Statistical Association |
|||
|volume=58 |issue=301 |year=1963 |pages=236–244 |
|||
|mr=0148188 |
|||
|jstor=2282967 |
|||
}}</ref> |
|||
* The probability that candidate clusters spawn from the same distribution function (V-linkage). |
* The probability that candidate clusters spawn from the same distribution function (V-linkage). |
||
* The product of in-degree and out-degree on a k-nearest-neighbour graph (graph degree linkage).<ref>{{Cite |
* The product of in-degree and out-degree on a k-nearest-neighbour graph (graph degree linkage).<ref>{{Cite book|last1=Zhang|first1=Wei|last2=Wang|first2=Xiaogang|last3=Zhao|first3=Deli|last4=Tang|first4=Xiaoou|title=Computer Vision – ECCV 2012 |chapter=Graph Degree Linkage: Agglomerative Clustering on a Directed Graph |date=2012|editor-last=Fitzgibbon|editor-first=Andrew|editor2-last=Lazebnik|editor2-first=Svetlana|editor2-link= Svetlana Lazebnik |editor3-last=Perona|editor3-first=Pietro|editor4-last=Sato|editor4-first=Yoichi|editor5-last=Schmid|editor5-first=Cordelia|series=Lecture Notes in Computer Science|language=en|publisher=Springer Berlin Heidelberg|volume=7572|pages=428–441|doi=10.1007/978-3-642-33718-5_31|isbn=9783642337185|arxiv=1208.5092|bibcode=2012arXiv1208.5092Z|s2cid=14751}} See also: https://github.com/waynezhanghk/gacluster</ref> |
||
* The increment of some cluster descriptor (i.e., a quantity defined for measuring the quality of a cluster) after merging two clusters.<ref>{{cite journal |first1=W. |last1=Zhang |first2=D. |last2=Zhao |first3=X. |last3=Wang |title=Agglomerative clustering via maximum incremental path integral |journal=Pattern Recognition |volume=46 |issue=11 |pages=3056–65 |date=2013 |doi=10.1016/j.patcog.2013.04.013 |citeseerx=10.1.1.719.5355 |bibcode=2013PatRe..46.3056Z}}</ref><ref>{{cite book |last1=Zhao |first1=D. |last2=Tang |first2=X. |chapter=Cyclizing clusters via zeta function of a graph |chapter-url= |title=NIPS'08: Proceedings of the 21st International Conference on Neural Information Processing Systems |date=2008 |isbn=9781605609492 |pages=1953–60 |citeseerx=10.1.1.945.1649}}</ref><ref>{{cite journal |first1=Y. |last1=Ma |first2=H. |last2=Derksen |first3=W. |last3=Hong |first4=J. |last4=Wright |title=Segmentation of Multivariate Mixed Data via Lossy Data Coding and Compression |journal=IEEE Transactions on Pattern Analysis and Machine Intelligence |volume=29 |issue=9 |pages=1546–62 |date=2007 |doi=10.1109/TPAMI.2007.1085 |pmid=17627043 |hdl=2142/99597 |s2cid=4591894 |hdl-access=free }}</ref> |
* The increment of some cluster descriptor (i.e., a quantity defined for measuring the quality of a cluster) after merging two clusters.<ref>{{cite journal |first1=W. |last1=Zhang |first2=D. |last2=Zhao |first3=X. |last3=Wang |title=Agglomerative clustering via maximum incremental path integral |journal=Pattern Recognition |volume=46 |issue=11 |pages=3056–65 |date=2013 |doi=10.1016/j.patcog.2013.04.013 |citeseerx=10.1.1.719.5355 |bibcode=2013PatRe..46.3056Z}}</ref><ref>{{cite book |last1=Zhao |first1=D. |last2=Tang |first2=X. |chapter=Cyclizing clusters via zeta function of a graph |chapter-url= |title=NIPS'08: Proceedings of the 21st International Conference on Neural Information Processing Systems |date=2008 |isbn=9781605609492 |pages=1953–60 |publisher=Curran |citeseerx=10.1.1.945.1649}}</ref><ref>{{cite journal |first1=Y. |last1=Ma |first2=H. |last2=Derksen |first3=W. |last3=Hong |first4=J. |last4=Wright |title=Segmentation of Multivariate Mixed Data via Lossy Data Coding and Compression |journal=IEEE Transactions on Pattern Analysis and Machine Intelligence |volume=29 |issue=9 |pages=1546–62 |date=2007 |doi=10.1109/TPAMI.2007.1085 |pmid=17627043 |hdl=2142/99597 |s2cid=4591894 |hdl-access=free }}</ref> |
||
== Discussion == |
|||
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. |
|||
== Agglomerative clustering example == |
== Agglomerative clustering example == |
||
Line 104: | Line 94: | ||
For example, suppose this data is to be clustered, and the [[Euclidean distance]] is the [[Metric (mathematics)|distance metric]]. |
For example, suppose this data is to be clustered, and the [[Euclidean distance]] is the [[Metric (mathematics)|distance metric]]. |
||
The hierarchical clustering [[dendrogram]] would be |
The hierarchical clustering [[dendrogram]] would be: |
||
[[Image:Hierarchical clustering simple diagram.svg|frame|none|Traditional representation]] |
[[Image:Hierarchical clustering simple diagram.svg|frame|none|Traditional representation]] |
||
Line 132: | Line 122: | ||
== Divisive clustering == |
== Divisive clustering == |
||
The basic principle of divisive clustering was published as the DIANA (DIvisive ANAlysis |
The basic principle of divisive clustering was published as the DIANA (DIvisive ANAlysis clustering) algorithm.<ref>{{cite book |first1=L. |last1=Kaufman |first2=P.J. |last2=Rousseeuw |chapter=6. Divisive Analysis (Program DIANA) |title=Finding Groups in Data: An Introduction to Cluster Analysis |chapter-url=https://books.google.com/books?id=YeFQHiikNo0C&pg=PA253 |orig-year=1990 |date=2009 |publisher=Wiley |isbn=978-0-470-31748-8 |pages=253–279}}</ref> Initially, all data is in the same cluster, and the largest cluster is split until every object is separate. |
||
Because there exist <math>O(2^n)</math> 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. |
Because there exist <math>O(2^n)</math> 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: |
|||
# Let <math>C_0 = \{1\dots n\}</math> be the set of all <math>n</math> object indices and <math>\mathcal{C} = \{C_0\}</math> the set of all formed clusters so far. |
|||
# Iterate the following until <math>|\mathcal{C}| = n</math>: |
|||
## Find the current cluster with 2 or more objects that has the largest diameter: <math>C_* = \arg\max_{C\in \mathcal{C}} \max_{i_1,i_2\in C} \delta(i_1,i_2)</math> |
|||
## Find the object in this cluster with the most dissimilarity to the rest of the cluster: <math>i^* = \arg\max_{i\in C_*} \frac{1}{|C_*|-1}\sum_{j\in C_*\setminus\{i\}} \delta(i,j)</math> |
|||
## Pop <math>i^*</math> from its old cluster <math>C_*</math> and put it into a new ''splinter group'' <math>C_\textrm{new} = \{i^*\}</math>. |
|||
## As long as <math>C_*</math> isn't empty, keep migrating objects from <math>C_*</math> to add them to <math>C_\textrm{new}</math>. To choose which objects to migrate, don't just consider dissimilarity to <math>C_*</math>, but also adjust for dissimilarity to the splinter group: let <math>i^* = \arg\max_{i\in C} D(i)</math> where we define <math>D(i) = \frac{1}{|C_*|-1}\sum_{j\in C_*\setminus\{i\}} \delta(i,j) - \frac{1}{|C_\textrm{new}|}\sum_{j\in C_\textrm{new}} \delta(i,j)</math>, then either stop iterating when <math>D(i^*) < 0</math>, or migrate <math>i^*</math>. |
|||
## Add <math>C_\textrm{new}</math> to <math>\mathcal{C}</math>. |
|||
Intuitively, <math>D(i)</math> 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 <math>C_\textrm{new}</math> be a child of the hollowed-out cluster <math>C_*</math> each time. This constructs a tree with <math>C_0</math> as its root and <math>n</math> unique single-object clusters as its leaves. |
|||
== Software == |
== Software == |
||
Line 148: | Line 154: | ||
* [[GNU Octave|Octave]], the [[GNU]] analog to [[MATLAB]] implements hierarchical clustering in function "linkage". |
* [[GNU Octave|Octave]], the [[GNU]] analog to [[MATLAB]] implements hierarchical clustering in function "linkage". |
||
* [[Orange (software)|Orange]], a data mining software suite, includes hierarchical clustering with interactive dendrogram visualisation. |
* [[Orange (software)|Orange]], a data mining software suite, includes hierarchical clustering with interactive dendrogram visualisation. |
||
* [[R (programming language)|R]] has built-in functions<ref>{{Cite web |title=hclust function - RDocumentation |url=https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/hclust |access-date=2022-06-07 |website=www.rdocumentation.org |language=en}}</ref> and packages that provide functions for hierarchical clustering.<ref>{{Citation | |
* [[R (programming language)|R]] has built-in functions<ref>{{Cite web |title=hclust function - RDocumentation |url=https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/hclust |access-date=2022-06-07 |website=www.rdocumentation.org |language=en}}</ref> and packages that provide functions for hierarchical clustering.<ref>{{Citation |last1=Galili |first1=Tal |title=dendextend: Extending 'dendrogram' Functionality in R|date=2021-10-28 |url=https://cran.r-project.org/package=dendextend |access-date=2022-06-07 |last2=Benjamini |first2=Yoav |last3=Simpson |first3=Gavin |last4=Jefferis |first4=Gregory}}</ref><ref>{{Cite web|last1=Paradis|first1=Emmanuel|display-authors=etal |title=ape: Analyses of Phylogenetics and Evolution|url=https://cran.r-project.org/web/packages/ape/index.html|access-date=2022-12-28}}</ref><ref>{{Cite web|last1=Fernández|first1=Alberto|last2=Gómez|first2=Sergio|date=2021-09-12|title=mdendro: Extended Agglomerative Hierarchical Clustering|url=https://sergio-gomez.github.io/mdendro/|access-date=2022-12-28}}</ref> |
||
* [[SciPy]] implements hierarchical clustering in Python, including the efficient SLINK algorithm. |
* [[SciPy]] implements hierarchical clustering in Python, including the efficient SLINK algorithm. |
||
* [[scikit-learn]] also implements hierarchical clustering in Python. |
* [[scikit-learn]] also implements hierarchical clustering in Python. |
Latest revision as of 07:23, 11 November 2024
Part of a series on |
Machine learning and data mining |
---|
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:
- Agglomerative: This is a "bottom-up" approach: Each observation starts in its own cluster, and pairs of clusters are merged as one moves up the hierarchy.
- Divisive: This is a "top-down" approach: All observations start in one cluster, and splits are performed recursively as one moves down the hierarchy.
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 ) can be guaranteed to find the optimum solution.[citation needed]
Complexity
[edit]The standard algorithm for hierarchical agglomerative clustering (HAC) has a time complexity of and requires memory, which makes it too slow for even medium data sets. However, for some special cases, optimal efficient agglomerative methods (of complexity ) 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 , an improvement on the aforementioned bound of , 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 total running time with space.[4]
Divisive clustering with an exhaustive search is , but it is common to use faster heuristics to choose splits, such as k-means.
Cluster Linkage
[edit]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]
Names | Formula |
---|---|
Maximum or complete-linkage clustering | |
Minimum or single-linkage clustering | |
Unweighted average linkage clustering (or UPGMA) | |
Weighted average linkage clustering (or WPGMA) | |
Centroid linkage clustering, or UPGMC | where and are the centroids of A resp. B. |
Median linkage clustering, or WPGMC | where |
Versatile linkage clustering[7] | |
Ward linkage,[8] Minimum Increase of Sum of Squares (MISSQ)[9] | |
Minimum Error Sum of Squares (MNSSQ)[9] | |
Minimum Increase in Variance (MIVAR)[9] | |
Minimum Variance (MNVAR)[9] | |
Hausdorff linkage[10] | |
Minimum Sum Medoid linkage[11] | such that m is the medoid of the resulting cluster |
Minimum Sum Increase Medoid linkage[11] | |
Medoid linkage[12][13] | where , are the medoids of the previous clusters |
Minimum energy clustering |
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:
- The probability that candidate clusters spawn from the same distribution function (V-linkage).
- The product of in-degree and out-degree on a k-nearest-neighbour graph (graph degree linkage).[14]
- The increment of some cluster descriptor (i.e., a quantity defined for measuring the quality of a cluster) after merging two clusters.[15][16][17]
Agglomerative clustering example
[edit]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 {a} {b c} {d e} {f}. Cutting after the third row will yield clusters {a} {b c} {d e f}, 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 {a} {b} {c} {d} {e} and {f}. 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 {a}, {b, c}, {d}, {e} and {f}, and want to merge them further. To do that, we need to take the distance between {a} and {b c}, and therefore define the distance between two clusters. Usually the distance between two clusters and is one of the following:
- The maximum distance between elements of each cluster (also called complete-linkage clustering):
- The minimum distance between elements of each cluster (also called single-linkage clustering):
- The mean distance between elements of each cluster (also called average linkage clustering, used e.g. in UPGMA):
- The sum of all intra-cluster variance.
- The increase in variance for the cluster being merged (Ward's method[8])
- The probability that candidate clusters spawn from the same distribution function (V-linkage).
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.[18]
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[19] (inversions, departures from ultrametricity) may occur.
Divisive clustering
[edit]The basic principle of divisive clustering was published as the DIANA (DIvisive ANAlysis clustering) algorithm.[20] Initially, all data is in the same cluster, and the largest cluster is split until every object is separate. Because there exist 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:
- Let be the set of all object indices and the set of all formed clusters so far.
- Iterate the following until :
- Find the current cluster with 2 or more objects that has the largest diameter:
- Find the object in this cluster with the most dissimilarity to the rest of the cluster:
- Pop from its old cluster and put it into a new splinter group .
- As long as isn't empty, keep migrating objects from to add them to . To choose which objects to migrate, don't just consider dissimilarity to , but also adjust for dissimilarity to the splinter group: let where we define , then either stop iterating when , or migrate .
- Add to .
Intuitively, 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 be a child of the hollowed-out cluster each time. This constructs a tree with as its root and unique single-object clusters as its leaves.
Software
[edit]Open source implementations
[edit]- ALGLIB implements several hierarchical clustering algorithms (single-link, complete-link, Ward) in C++ and C# with O(n²) memory and O(n³) run time.
- ELKI includes multiple hierarchical clustering algorithms, various linkage strategies and also includes the efficient SLINK,[2] CLINK[3] and Anderberg algorithms, flexible cluster extraction from dendrograms and various other cluster analysis algorithms.
- Julia has an implementation inside the Clustering.jl package.[21]
- Octave, the GNU analog to MATLAB implements hierarchical clustering in function "linkage".
- Orange, a data mining software suite, includes hierarchical clustering with interactive dendrogram visualisation.
- R has built-in functions[22] and packages that provide functions for hierarchical clustering.[23][24][25]
- SciPy implements hierarchical clustering in Python, including the efficient SLINK algorithm.
- scikit-learn also implements hierarchical clustering in Python.
- Weka includes hierarchical cluster analysis.
Commercial implementations
[edit]- MATLAB includes hierarchical cluster analysis.
- SAS includes hierarchical cluster analysis in PROC CLUSTER.
- Mathematica includes a Hierarchical Clustering Package.
- NCSS includes hierarchical cluster analysis.
- SPSS includes hierarchical cluster analysis.
- Qlucore Omics Explorer includes hierarchical cluster analysis.
- Stata includes hierarchical cluster analysis.
- CrimeStat includes a nearest neighbor hierarchical cluster algorithm with a graphical output for a Geographic Information System.
See also
[edit]- Binary space partitioning
- Bounding volume hierarchy
- Brown clustering
- Cladistics
- Cluster analysis
- Computational phylogenetics
- CURE data clustering algorithm
- Dasgupta's objective
- Dendrogram
- Determining the number of clusters in a data set
- Hierarchical clustering of networks
- Locality-sensitive hashing
- Nearest neighbor search
- Nearest-neighbor chain algorithm
- Numerical taxonomy
- OPTICS algorithm
- Statistical distance
- Persistent homology
References
[edit]- ^ Nielsen, Frank (2016). "8. Hierarchical Clustering". Introduction to HPC with MPI for Data Science. Springer. pp. 195–211. ISBN 978-3-319-21903-5.
- ^ a b R. Sibson (1973). "SLINK: an optimally efficient algorithm for the single-link cluster method" (PDF). The Computer Journal. 16 (1). British Computer Society: 30–34. doi:10.1093/comjnl/16.1.30.
- ^ a b D. Defays (1977). "An efficient algorithm for a complete-link method". The Computer Journal. 20 (4). British Computer Society: 364–6. doi:10.1093/comjnl/20.4.364.
- ^ Eppstein, David (2001-12-31). "Fast hierarchical clustering and other applications of dynamic closest pairs". ACM Journal of Experimental Algorithmics. 5: 1–es. arXiv:cs/9912014. doi:10.1145/351827.351829. ISSN 1084-6654.
- ^ "The CLUSTER Procedure: Clustering Methods". SAS/STAT 9.2 Users Guide. SAS Institute. Retrieved 2009-04-26.
- ^ 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. doi:10.1007/s00357-005-0012-9. S2CID 206960007.
- ^ Fernández, Alberto; Gómez, Sergio (2020). "Versatile linkage: a family of space-conserving strategies for agglomerative hierarchical clustering". Journal of Classification. 37 (3): 584–597. arXiv:1906.09222. doi:10.1007/s00357-019-09339-z. S2CID 195317052.
- ^ a b Ward, Joe H. (1963). "Hierarchical Grouping to Optimize an Objective Function". Journal of the American Statistical Association. 58 (301): 236–244. doi:10.2307/2282967. JSTOR 2282967. MR 0148188.
- ^ a b c d Podani, János (1989), Mucina, L.; Dale, M. B. (eds.), "New combinatorial clustering methods", Numerical syntaxonomy, Dordrecht: Springer Netherlands, pp. 61–77, doi:10.1007/978-94-009-2432-1_5, ISBN 978-94-009-2432-1, retrieved 2022-11-04
- ^ 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. 379 (2): 635–644. arXiv:physics/0504014. Bibcode:2007PhyA..379..635B. doi:10.1016/j.physa.2007.01.011. ISSN 0378-4371. S2CID 27093582.
- ^ a b Schubert, Erich (2021). HACAM: Hierarchical Agglomerative Clustering Around Medoids – and its Limitations (PDF). LWDA’21: Lernen, Wissen, Daten, Analysen September 01–03, 2021, Munich, Germany. pp. 191–204 – via CEUR-WS.
- ^ 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). pp. 400–403. doi:10.1109/SCIS-ISIS.2016.0091.
- ^ Herr, Dominik; Han, Qi; Lohmann, Steffen; Ertl, Thomas (2016). Visual Clutter Reduction through Hierarchy-based Projection of High-dimensional Labeled Data (PDF). Graphics Interface. Graphics Interface. doi:10.20380/gi2016.14. Retrieved 2022-11-04.
- ^ Zhang, Wei; Wang, Xiaogang; Zhao, Deli; Tang, Xiaoou (2012). "Graph Degree Linkage: Agglomerative Clustering on a Directed Graph". In Fitzgibbon, Andrew; Lazebnik, Svetlana; Perona, Pietro; Sato, Yoichi; Schmid, Cordelia (eds.). Computer Vision – ECCV 2012. Lecture Notes in Computer Science. Vol. 7572. Springer Berlin Heidelberg. pp. 428–441. arXiv:1208.5092. Bibcode:2012arXiv1208.5092Z. doi:10.1007/978-3-642-33718-5_31. ISBN 9783642337185. S2CID 14751. See also: https://github.com/waynezhanghk/gacluster
- ^ Zhang, W.; Zhao, D.; Wang, X. (2013). "Agglomerative clustering via maximum incremental path integral". Pattern Recognition. 46 (11): 3056–65. Bibcode:2013PatRe..46.3056Z. CiteSeerX 10.1.1.719.5355. doi:10.1016/j.patcog.2013.04.013.
- ^ Zhao, D.; Tang, X. (2008). "Cyclizing clusters via zeta function of a graph". NIPS'08: Proceedings of the 21st International Conference on Neural Information Processing Systems. Curran. pp. 1953–60. CiteSeerX 10.1.1.945.1649. ISBN 9781605609492.
- ^ Ma, Y.; Derksen, H.; Hong, W.; Wright, J. (2007). "Segmentation of Multivariate Mixed Data via Lossy Data Coding and Compression". IEEE Transactions on Pattern Analysis and Machine Intelligence. 29 (9): 1546–62. doi:10.1109/TPAMI.2007.1085. hdl:2142/99597. PMID 17627043. S2CID 4591894.
- ^ Fernández, Alberto; Gómez, Sergio (2008). "Solving Non-uniqueness in Agglomerative Hierarchical Clustering Using Multidendrograms". Journal of Classification. 25 (1): 43–65. arXiv:cs/0608049. doi:10.1007/s00357-008-9004-x. S2CID 434036.
- ^ Legendre, P.; Legendre, L.F.J. (2012). "Cluster Analysis §8.6 Reversals". Numerical Ecology. Developments in Environmental Modelling. Vol. 24 (3rd ed.). Elsevier. pp. 376–7. ISBN 978-0-444-53868-0.
- ^ Kaufman, L.; Rousseeuw, P.J. (2009) [1990]. "6. Divisive Analysis (Program DIANA)". Finding Groups in Data: An Introduction to Cluster Analysis. Wiley. pp. 253–279. ISBN 978-0-470-31748-8.
- ^ "Hierarchical Clustering · Clustering.jl". juliastats.org. Retrieved 2022-02-28.
- ^ "hclust function - RDocumentation". www.rdocumentation.org. Retrieved 2022-06-07.
- ^ Galili, Tal; Benjamini, Yoav; Simpson, Gavin; Jefferis, Gregory (2021-10-28), dendextend: Extending 'dendrogram' Functionality in R, retrieved 2022-06-07
- ^ Paradis, Emmanuel; et al. "ape: Analyses of Phylogenetics and Evolution". Retrieved 2022-12-28.
- ^ Fernández, Alberto; Gómez, Sergio (2021-09-12). "mdendro: Extended Agglomerative Hierarchical Clustering". Retrieved 2022-12-28.
Further reading
[edit]- Kaufman, L.; Rousseeuw, P.J. (1990). Finding Groups in Data: An Introduction to Cluster Analysis (1 ed.). New York: John Wiley. ISBN 0-471-87876-6.
- Hastie, Trevor; Tibshirani, Robert; Friedman, Jerome (2009). "14.3.12 Hierarchical clustering". The Elements of Statistical Learning (2nd ed.). New York: Springer. pp. 520–8. ISBN 978-0-387-84857-0. Archived from the original (PDF) on 2009-11-10. Retrieved 2009-10-20.