World Library  
Flag as Inappropriate
Email this Article

Hierarchical clustering

Article Id: WHEBN0000477573
Reproduction Date:

Title: Hierarchical clustering  
Author: World Heritage Encyclopedia
Language: English
Subject: Cluster analysis, Complete-linkage clustering, UPGMA, Consensus clustering, Diana
Collection: Data Clustering Algorithms, Network Analysis
Publisher: World Heritage Encyclopedia

Hierarchical clustering

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

  • 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 are usually presented in a dendrogram.

In the general case, the complexity of agglomerative clustering is O(n^3), which makes them too slow for large data sets. Divisive clustering with an exhaustive search is O(2^n), which is even worse. However, for some special cases, optimal efficient agglomerative methods (of complexity O(n^2)) are known: SLINK[2] for single-linkage and CLINK[3] for complete-linkage clustering.


  • Cluster dissimilarity 1
    • Metric 1.1
    • Linkage criteria 1.2
  • Discussion 2
  • Example for Agglomerative Clustering 3
  • Software 4
    • Open Source Implementations 4.1
    • Standalone implementations 4.2
    • Commercial 4.3
  • See also 5
  • Notes 6
  • References and further reading 7

Cluster dissimilarity

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 metric (a measure of distance between pairs of observations), 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 an appropriate metric will influence the shape of the clusters, as some elements may be close to one another according to one distance and farther away according to another. For example, in a 2-dimensional space, the distance between the point (1,0) and the origin (0,0) is always 1 according to the usual norms, but the distance between the point (1,1) and the origin (0,0) can be 2 under Manhattan distance, \scriptstyle\sqrt{2} under Euclidean distance, or 1 under maximum distance.

Some commonly used metrics for hierarchical clustering are:[4]

Names Formula
Euclidean distance \|a-b \|_2 = \sqrt{\sum_i (a_i-b_i)^2}
Squared Euclidean distance \|a-b \|_2^2 = \sum_i (a_i-b_i)^2
Manhattan distance \|a-b \|_1 = \sum_i |a_i-b_i|
maximum distance \|a-b \|_\infty = \max_i |a_i-b_i|
Mahalanobis distance \sqrt{(a-b)^{\top}S^{-1}(a-b)} 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.

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.

Linkage criteria

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:[5][6]

Names Formula
Maximum or complete-linkage clustering \max \, \{\, d(a,b) : a \in A,\, b \in B \,\}.
Minimum or single-linkage clustering \min \, \{\, d(a,b) : a \in A,\, b \in B \,\}.
Mean or average linkage clustering, or UPGMA \frac{1}{|A| |B|} \sum_{a \in A }\sum_{ b \in B} d(a,b).
Centroid linkage clustering, or UPGMC ||c_s - c_t || where c_s and c_t are the centroids of clusters s and t, respectively.
Minimum energy clustering \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

where d is the chosen metric. Other linkage criteria include:

  • The sum of all intra-cluster variance.
  • The decrease in variance for the cluster being merged (Ward's criterion).[7]
  • 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-neighbor graph (graph degree linkage).[8]
  • The increment of some cluster descriptor (i.e., a quantity defined for measuring the quality of a cluster) after merging two clusters.[9][10][11]


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.

Example for Agglomerative Clustering

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

Cutting the tree at a given height will give a partitioning clustering at a selected precision. In this example, cutting after the second row 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.

Raw data

The hierarchical clustering dendrogram would be as such:

Traditional representation

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 \mathcal{A} and \mathcal{B} is one of the following:

\max \{\, d(x,y) : x \in \mathcal{A},\, y \in \mathcal{B}\,\}.
\min \{\, d(x,y) : x \in \mathcal{A},\, y \in \mathcal{B} \,\}.
  • The mean distance between elements of each cluster (also called average linkage clustering, used e.g. in UPGMA):
{1 \over {|\mathcal{A}|\cdot|\mathcal{B}|}}\sum_{x \in \mathcal{A}}\sum_{ y \in \mathcal{B}} d(x,y).
  • The sum of all intra-cluster variance.
  • The decrease in variance for the cluster being merged (Ward's method[7])
  • The probability that candidate clusters spawn from the same distribution function (V-linkage).

Each agglomeration occurs at a greater distance between clusters than the previous agglomeration, and one can decide to stop clustering either when the clusters are too far apart to be merged (distance criterion) or when there is a sufficiently small number of clusters (number criterion).


Open Source Implementations

  • Cluster 3.0 provides a nice Graphical User Interface to access to different clustering routines and is available for Windows, Mac OS X, Linux, Unix.
  • Data Explorer is a free software with graphical interface that implements more than 30 statistical analyses including dendrograms. Written in javascript, works as a desktop application and in the browser.
  • 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.
  • Octave, the GNU analog to MATLAB implements hierarchical clustering in linkage function
  • Orange, a free data mining software suite, module orngClustering for scripting in Python, or cluster analysis through visual programming.
  • R has several functions for hierarchical clustering: see CRAN Task View: Cluster Analysis & Finite Mixture Models for more information.
  • SCaViS computing environment in Java that implements this algorithm.
  • scikit-learn implements a hierarchical clustering.
  • Weka includes hierarchical cluster analysis.

Standalone implementations

  • CrimeStat implements two hierarchical clustering routines, a nearest neighbor (Nnh) and a risk-adjusted(Rnnh).
  • figue is a JavaScript package that implements some agglomerative clustering functions (single-linkage, complete-linkage, average-linkage) and functions to visualize clustering output (e.g. dendrograms).
  • hcluster is a Python implementation, based on NumPy, which supports hierarchical clustering and plotting.
  • Hierarchical Agglomerative Clustering implemented as C# visual studio project that includes real text files processing, building of document-term matrix with stop words filtering and stemming.
  • MultiDendrograms An open source Java application for variable-group agglomerative hierarchical clustering, with graphical user interface.
  • Graph Agglomerative Clustering (GAC) toolbox implemented several graph-based agglomerative clustering algorithms.
  • Hierarchical Clustering Explorer provides tools for interactive exploration of multidimensional data.


  • MATLAB includes hierarchical cluster analysis.
  • SAS includes hierarchical cluster analysis in PROC CLUSTER.[12]
  • Mathematica includes a Hierarchical Clustering Package.
  • NCSS (statistical software) includes hierarchical cluster analysis.
  • SPSS includes hierarchical cluster analysis.
  • Qlucore Omics Explorer includes hierarchical cluster analysis.
  • Stata includes hierarchical cluster analysis.

See also


  1. ^ Rokach, Lior, and Oded Maimon. "Clustering methods." Data mining and knowledge discovery handbook. Springer US, 2005. 321-352.
  2. ^ "The DISTANCE Procedure: Proximity Measures". SAS/STAT 9.2 Users Guide.  
  3. ^ "The CLUSTER Procedure: Clustering Methods". SAS/STAT 9.2 Users Guide.  
  4. ^ Székely, G. J. and Rizzo, M. L. (2005) Hierarchical clustering via Joint Between-Within Distances: Extending Ward's Minimum Variance Method, Journal of Classification 22, 151-183.
  5. ^ a b Ward, Joe H. (1963). "Hierarchical Grouping to Optimize an Objective Function". Journal of the American Statistical Association 58 (301): 236–244.  
  6. ^ Zhang, et al. "Graph degree linkage: Agglomerative clustering on a directed graph." 12th European Conference on Computer Vision, Florence, Italy, October 7–13, 2012.
  7. ^ Zhang, et al. "Agglomerative clustering via maximum incremental path integral." Pattern Recognition (2013).
  8. ^ Zhao, and Tang. "Cyclizing clusters via zeta function of a graph."Advances in Neural Information Processing Systems. 2008.
  9. ^ Ma, et al. "Segmentation of multivariate mixed data via lossy data coding and compression." IEEE Transactions on Pattern Analysis and Machine Intelligence, 29(9) (2007): 1546-1562.
  10. ^

References and further reading

  • Kaufman, L.; Rousseeuw, P.J. (1990). Finding Groups in Data: An Introduction to Cluster Analysis (1 ed.). New York: John Wiley.  
  • Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007). "Section 16.4. Hierarchical Clustering by Phylogenetic Trees". Numerical Recipes: The Art of Scientific Computing (3rd ed.). New York: Cambridge University Press.  
  • Hierarchical Cluster Analysis
  • Free statistical software. An overview of statistical software and methods used in published microbiological studies
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.