# Agglomerative Hierarchical Clustering Algorithm

An Agglomerative Hierarchical Clustering Algorithm is a Hierarchical Clustering Algorithm in which each observation starts in its own cluster, and pairs of clusters are merged as one moves up the hierarchy.

## References

### 2019a

• (Wikipedia, 2019) ⇒ https://en.wikipedia.org/wiki/Hierarchical_clustering Retrieved:2019-5-19.
• 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.

The standard algorithm for hierarchical agglomerative clustering (HAC) has a time complexity of $\mathcal{O}(n^3)$ and requires $\mathcal{O}(n^2)$ memory, which makes it too slow for even medium data sets. However, for some special cases, optimal efficient agglomerative methods (of complexity $\mathcal{O}(n^2)$ ) are known: SLINKK[2] for single-linkage and CLINK[3] for complete-linkage clustering. With a heap the runtime of the general case can be reduced to $\mathcal{O}(n^2 \log n)$ at the cost of further increasing the memory requirements. In many programming languages, the memory overheads of this approach are too large to make it practically usable.

Except for the special case of single-linkage, none of the algorithms (except exhaustive search in $\mathcal{O}(2^n)$ ) can be guaranteed to find the optimum solution.

Divisive clustering with an exhaustive search is $\mathcal{O}(2^n)$ , but it is common to use faster heuristics to choose splits, such as k-means.

1. Rokach, Lior, and Oded Maimon. "Clustering methods." Data mining and knowledge discovery handbook. Springer US, 2005. 321-352.

### 2019b

• (Wikipedia, 2019) ⇒ https://en.wikipedia.org/wiki/Hierarchical_clustering#Agglomerative_clustering_example Retrieved:2019-5-19.
• For example, suppose this data is to be clustered, and the Euclidean distance is the distance metric.

The hierarchical clustering dendrogram would be as such:

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 $\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 increase in variance for the cluster being merged (Ward's method[1])
• 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 . 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 (inversions, departures from ultrametricity) may occur.
1. 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.

### 1984

• Day, William HE, and Herbert Edelsbrunner. "Efficient algorithms for agglomerative hierarchical clustering methods.” In: Journal of classification 1, no. 1 (1984): 7-24.