Keywords
Clustering, Hierarchy, Dendrogram, Gene Expression, Empirical
This article is included in the Bioinformatics gateway.
Clustering, Hierarchy, Dendrogram, Gene Expression, Empirical
Hierarchical clustering analysis (HCA) is an extensively studied field of unsupervised learning. Very useful in dimensionality reduction problems, we will study ways of using this clustering method with the aim of reducing (or removing) the need for human intervention.
The problem of human intervention stems from the fact that HCA is used when the correct number of clusters in a dataset is not known (otherwise we might use, for example, K-means). While the ability to cluster data with an unknown number of clusters is a powerful one, a researcher often needs to interpret the results - or cutoff the algorithm - to recover a meaningful cluster number. While our work was prompted by DNA microarray analysis and gene expression problems, these methods can be applied to general hierarchical clustering scenarios. Specifically, we analyze different existing automated methods for cutting off HCA and propose two new ones.
In Section 2 we discuss background material on HCA and the existing methods and in Section 3 we present some technical details on these methods and introduce our own. Section 4 contains results on simulated and actual data, and Section 5 examines data sampling procedures to improve accuracy.
Hierarchical clustering, briefly, seeks to pair up data points that are most similar to one another. With the agglomerative (or bottom-up) approach, we begin with N data points forming singleton clusters. For each point, we measure the distance between it and its N − 1 neighbors. The pair with the shortest distance between the two points is taken to form a new cluster. We then look at the distance between the N − 2 points remaining and the newly formed cluster, and again pair off the two points with the shortest distance (either adding a data point to our 2-cluster, or forming another cluster from two new data points). This process is repeated until there is a single cluster with N points (regardless of the absolute distance between points).
Naturally, this is a very good dimensionality reduction algorithm. Unfortunately, it continues until the data is flattened to 1 dimension. In cases where there are n ≥ 2 clusters, this is problematic.
The results of a HCA are often expressed as a dendrogram, a tree-like graph that contains vital information about the distances measured in the clustering and the pairings generated. An example of a dendrogram is shown in Figure 1. Briefly, horizontal lines denote pairings, and the height of those lines represent the distance that needs to be bridged in order to cluster the points together. That is, the smaller the height (or jump) of a pairing, the closer the points were to begin with.
Our goal is to find a way to stop the algorithm from arbitrarily flattening our data to 1 dimension. If another run would cluster two very dissimilar points together, it likely isn’t a scientifically sound choice. In that case we would stop the algorithm and keep the cluster structure built up to that point.
The problem of cutting off a dendrogram is one that researchers encounter often, but there are no reliable automated methods for doing so 1. Often, the gap statistic is the only proposed automated method, as in 1. As such, many researchers inspect the finished dendrogram and manually select a cutoff point, based on their own judgment. Apart from the obviously slow nature of this exercise, there is also the question of human error to consider - as well as bias. In cases where the cutoff is not easily determined, two different researchers may arrive at different conclusions as to the correct number of clusters - which could both be incorrect. Algorithmic approaches aim to eliminate this, and range from simpler methods to more complex ones. An excellent summary of existing methods is given in 2, which is referenced in 3.
The latter, more importantly, develops the gap statistic. We present the technical aspects in Section 3, but quickly discuss some properties here. First, the gap statistic is one of few methods that is capable of accurately estimating single clusters (in the case where all our data belongs to one cluster), a situation often undefined for other methods1. While it is rather precise overall, it requires the use of a “reference distribution”, which must be chosen by the researcher. In 3, the authors put forward that the uniform distribution is in fact the best choice for unimodal distributions. A powerful result, it is still limited in other cases, and thus many researchers still take the manual approach. However, it generally outperforms other complex methods (see 3) and, as such, we focus on the gap statistic.
On the other side of the complexity spectrum, are variants of the “elbow method". The elbow method explains the variance in data as a function of the number of clusters assigned. The more clusters assigned, the more variance that can be explained. However, as we add more clusters we begin to get diminishing returns and each new cluster explains less and less of the variance - we choose the point where returns begin to diminish as the number of clusters. A variant of this method, often applied to dendrograms, looks for the largest acceleration of distance growth4. While this method is very flexible, it cannot handle the single-cluster case4.
We look at both the elbow method variant and the gap statistic, as well as our own 2 methods. While there are many other methods to compare to, the gap statistic is quite representative of a successful (if more complex) solution - and tends to outperform other known methods3. The elbow method is representative of the more accepted simple approaches. In all tests considered in this paper, an agglomerative hierarchy, with average linkage and euclidean distance measure is used.
The gap statistic is constructed from the within-cluster distances, and comparing their sum to the expected value under a null distribution. Specifically, as given in 3, for r clusters Cr
where, with nr = |Cr|,That is, we are looking at the sum of the within-cluster distances d, across all r clusters Cr. Computationally, we estimate the gap statistic and find the number of clusters to be (as per 3)
where sk is the standard error from the estimation of Gap(k). As mentioned3, considers both a uniform distribution approach and a principal component construction. In many cases, the uniform distribution performs better, and this is used here.This variant of the elbow method, which looks at the acceleration, is seen in 4. A straightforward method, we simply look at the acceleration in jump sizes. So given the set of distances from our clustering {d1, … , dN}, the acceleration can be written as
We choose our number of clusters as the jump with the highest acceleration, giving us
While very simple and very fast, this method will never find the endpoints, ie, the N singleton clusters and the single N-element cluster cases.
The first method we propose is based on the empirical distribution of jump sizes. Specifically, we use the mode of the distribution D = {d1, … , dN}, denoted D̂, adjusted by the standard deviation (σD). Our motivation is that the most common jump size likely does not represent a good cutoff point, and we should consider a higher jump threshold. As such, we take the number of clusters to be
where α is a parameter that can be tuned. Naturally, tuning α would require human intervention or a training dataset. As such, we set it to 3 arbitrarily for a first look at the method’s viability.Our second method is even simpler, but is surprisingly absent from the literature. Inspired by the elbow method, we look at the maximum jump difference - as opposed to acceleration. Our number of clusters is then given by
This method shares the elbow method’s drawback that it cannot solve the single cluster case (though it can handle singleton clusters), but we thought it prudent to examine as the literature seemed to focus on acceleration and not velocity.
We present results of simulations on several numbers of true clusters, drawn from a 2-dimensional normal distribution. Each cluster is comprised of 100 samples. We are most interested in tracking the success rate and the error size given an incorrect estimate. That is, how often can we correctly estimate the number of clusters k and when we can’t, by how much are we off? Formally, this is given by
andThe data used was drawn from a standard normal distribution, with cluster centers at (−3, −3), (3, 3), (−3, 3), (3, −3), shown in Figure 2. In the case of 1 cluster, the first is taken, for 2 clusters, the first two, and so on. We present the results of the methods on n = 200 simulations below in Table 1–Table 3, with the best results in bold.
k | ||||
---|---|---|---|---|
1 | 3.720 | 1.110 | 2.965 | 4.505 |
2 | 2.000 | 2.000 | 2.000 | 2.645 |
3 | 3.050 | 3.050 | 3.015 | 4.725 |
4 | 3.915 | 4.060 | 4.010 | 6.280 |
k | SE | SG | SD | SM |
---|---|---|---|---|
1 | 0.000 | 0.910 | 0.000 | 0.000 |
2 | 1.000 | 1.000 | 1.000 | 0.465 |
3 | 0.955 | 0.960 | 0.985 | 0.100 |
4 | 0.920 | 0.940 | 0.990 | 0.055 |
k | EE | EG | ED | EM |
---|---|---|---|---|
1 | 2.720 | 1.222 | 1.965 | 3.505 |
2 | 0.000 | 0.000 | 0.000 | 1.206 |
3 | 1.111 | 1.250 | 1.000 | 1.917 |
4 | 1.688 | 1.000 | 1.000 | 2.413 |
As shown, the best performing methods so far are the gap statistic and, surprisingly, the maximum difference.
The maximum difference method has a near perfect success rate on this simple example, besting the gap statistic in most areas. As noted though, it suffers from the same problem as the elbow method in that it cannot handle the single-cluster case. It is our recommendation that if the reader suspects their data may be a single cluster, they should consider the gap statistic method. Note, however, that it is much more computationally intensive. As measured by Python’s timeit function, by a factor of ~ 50000.
To get a better sense for the behavior of these methods, we look at clusters drawn from normal distributions with different parameters. For the clusters centered at (−3, −3), (3, 3), (−3, 3), (3, −3), we scale the standard deviations to use, respectively: 𝟙2, 𝟙2, 2𝟙2, 0.5𝟙2. Hopefully, these different distributions will stress the methods, highlight any weaknesses, and likely serve as a better proxy for real data. The results are detailed in Table 4–Table 6.
k | ||||
---|---|---|---|---|
1 | 3.710 | 1.100 | 3.035 | 4.450 |
2 | 2.000 | 2.000 | 2.000 | 2.625 |
3 | 3.170 | 3.000 | 3.060 | 6.055 |
4 | 3.940 | 4.140 | 4.005 | 5.780 |
k | SE | SG | SD | SM |
---|---|---|---|---|
1 | 0.000 | 0.910 | 0.000 | 0.000 |
2 | 1.000 | 1.000 | 1.000 | 0.475 |
3 | 0.840 | 1.000 | 0.920 | 0.005 |
4 | 0.955 | 0.880 | 0.995 | 0.085 |
k | EE | EG | ED | EM |
---|---|---|---|---|
1 | 2.710 | 1.111 | 2.035 | 3.450 |
2 | 0.000 | 0.000 | 0.000 | 1.190 |
3 | 1.063 | 0.000 | 1.000 | 3.070 |
4 | 1.778 | 1.167 | 1.000 | 1.945 |
In this more complicated case, we see similar results. The 3-cluster case (in this example) seems problematic for our method and the elbow method. The gap statistic once again performs well for the single-cluster scenario, but shows some weakness at 4 clusters. Overall, it seems that for k = 2, 3, 4 clusters, the maximum difference method at the very least is equal to the gap statistic, and improves on it in certain cases.
Returning to the equal-distribution 4-cluster problem, we now look at how the metrics evolve the distance between the clusters is increased. On the x-axis in Figure 3, a value of m corresponds to a cluster arrangement with coordinates: (−m/2, −m/2), (m/2, m/2), (−m/2, m/2), (m/2, −m/2). We expect all methods to perform better as the clusters drift further apart, since they are then more distinct.
This is indeed the case for the elbow, maximum difference and mode methods, which converge to a success rate of 1 and an error size of 0 (note some increased stability in the maximum difference). However, the gap statistic appears to do worse as the clusters separate - which could point to some underlying issues and should be explored more fully.
As mentioned in Section 1, our primary motivation for this problem was that of DNA microarray data and gene expression problems. It is also always prudent to test new methods using real data. As such (and to help with reproducibility), we test our methods on the ExpressionSet data from the R package Biobase (Bioconductor) v3.2,5. This is a sample of 26 different elements, with reconstructions presented in Figure 4 and Figure 5.
In this case, the maximum difference and elbow methods were in agreement and selected k̂E = k̂D = 3 clusters (with samples R and Z being singleton clusters). The mode, however, chose to add Z into the main cluster, producing k̂M = 2 final clusters. O the other hand, the gp statistic selects only k̂G = 1 cluster.
The author finds both the mode and gap results to be somewhat dubious - but they highlight an important issue. How can we know that a clustering is correct? Even if we examine the dendrogram as we did here, it is likely that in many examples the cutoff point could be debated. In this dataset, we find it more challenging to determine a correct clustering between 2 and 3 clusters - though 3 seems more natural to the author. This calls back to the previously mentioned issue with manual cutoff selection.
In an effort to improve our new methods, we look at data sampling. Inspired by cross-validation methods, we will randomly sample points L = 100 times. For each of the L samples j, we then run our method and get a We then set our estimated number of clusters to be
While this requires running our method L times, for L = 100, it is still roughly 500 times faster that the gap statistic. Hopefully, this will improve our methods by averaging out any outlying errors or points in our data.
We present results on the same k = 2, 3, 4 cluster construction detailed above, each with the same distribution (Table 7–Table 9). Due to computational times, we did not perform data mixing on the gap statistic. Though given that these methods are much faster even with mixing, we believe that comparing them remains a fruitful exercise. We provide the gap statistic results from Table 1–Table 3 here for convenience.
k | ||||
---|---|---|---|---|
2 | 2.000 | 2.000 | 2.000 | 2.015 |
3 | 3.000 | 3.050 | 3.000 | 3.080 |
4 | 4.000 | 4.060 | 4.000 | 4.065 |
k | SG | |||
---|---|---|---|---|
2 | 1.000 | 1.000 | 1.000 | 0.985 |
3 | 1.000 | 0.960 | 1.000 | 0.920 |
4 | 1.000 | 0.940 | 1.000 | 0.935 |
k | EG | |||
---|---|---|---|---|
2 | 0.000 | 0.000 | 0.000 | 1.000 |
3 | 0.000 | 1.250 | 0.000 | 1.000 |
4 | 0.000 | 1.000 | 0.000 | 1.000 |
As shown above, both the elbow method and the maximum difference seem to perfectly capture the simulated data. Perhaps even more surprising, the mode method now has results that are comparable to the gap statistic and not far behind the other methods.
We now return to the ExpressionSet to see if we can come to a consensus on its clustering. We run the same and L = 100 mixing as for the simulated data to obtain Figure 6.
With mixing, there are slight differences in clustering. The elbow and maximum difference methods now agree on 2 clusters instead of 3. The mode method agrees with the gap statistic and sets the number of clusters to 1. Again, we find it difficult to argue in favor of 1 cluster, but maintain that 2 or 3 clusters seem viable - with a preference for 3. It is possible we somehow over-mixed the data when working with such a small sample.
Our data mixing procedure resembles leave N − M out cross validation. In that spirit, let’s examine a method resembling leave one out cross validation (note that computation times will now increase with data size). In our case, this means taking M = 1 and removing each data point once (in a sense, L = N). For each “sampled" set (of N − 1 points), we compute the number of clusters and again take the mode of the L sample cluster numbers as our estimate. With this we obtain Table 10–Table 12 and Figure 7.
k | ||||
---|---|---|---|---|
2 | 2.000 | 2.000 | 2.000 | 2.660 |
3 | 3.040 | 3.050 | 3.000 | 4.630 |
4 | 3.900 | 4.060 | 4.000 | 6.180 |
k | ||||
---|---|---|---|---|
2 | 1.000 | 1.000 | 1.000 | 0.465 |
3 | 0.960 | 0.960 | 1.000 | 0.135 |
4 | 0.940 | 0.940 | 1.000 | 0.055 |
k | ||||
---|---|---|---|---|
2 | 0.000 | 0.000 | 0.000 | 1.234 |
3 | 1.000 | 1.250 | 0.000 | 1.884 |
4 | 2.000 | 1.000 | 0.000 | 2.307 |
While the maximum difference method seems robust in the face of different sampling, it seems that this exercise has revealed some instability in the mode method, which has reverted back to a lackluster performance. To a much lesser extent, the elbow method has some trouble as well. It seems more likely that the choice of sampling parameters could be the cause of the clustering in the Biobase data in Figure 6. More generally, we should look into determining optimal mixing parameters M and L and/or their impact on these methods.
This mixing method does appear to perform better for the ExpressionSet than the previous choice of mixing parameters, which seems to confirm our hypothesis that there is perhaps an oversampling effect, or something along those lines which must be explored more fully.
We have developed two new empirical methods for clustering data in a hierarchical framework. While our methods are substantially faster than the existing gap statistic, they do not handle the single-cluster case. In other cases, our maximum difference method is at least comparable to the gap statistic and outperforms the elbow method.
In addition, the use of the data mixing procedure presented here can greatly improve performance (especially for the mode method), leading to the maximum difference method outperforming the other 3. Lastly, these methods can be implemented in a few lines of code and should allow researchers to quickly utilize them at a low computational cost.
In the future we will study the possibility of finding optimal mixing numbers M and L and the impact of the choice of these parameters of our results. Hopefully, they are related to the instability detected in the mode method when using M = 1 in our mixing procedure.
We provide base code to generate the simulated data used in this paper. The code is written in Python 2.7.
from scipy.cluster.hierarchy import linkage
import numpy as np
p = 2 #dimension of the data
n = 100 #number of samples in each cluster
k = 4 #number of clusters
a = np.random.multivariate_normal(\\
[-3 for _ in range(0,p)],\\
np.identity(p), size=[n,])
b = np.random.multivariate_normal(\\
[3 for _ in range(0,p)],\\
np.identity(p), size=[n,])
#c can be changed to use 2*np.identity(p)
c = np.random.multivariate_normal(\\
[-3,3], np.identity(p), size=[n,])
#d can be changed to use 0.5*np.identity(p)
d = np.random.multivariate_normal(\\
[3,-3], np.identity(p), size=[n,])
#X contains the necessary data
X = np.concatenate((a, b, c, d),)
#for reference as to data format usage
Z = linkage(X,'average')
In order to access the ExpressionSet data, we use the following R code.
library(Biobase)
getClass("ExpressionSet")
#dat contains the necessary data
dat = t(exprs(sample.ExpressionSet))
Views | Downloads | |
---|---|---|
F1000Research | - | - |
PubMed Central
Data from PMC are received and updated monthly.
|
- | - |
Competing Interests: No competing interests were disclosed.
Competing Interests: No competing interests were disclosed.
Competing Interests: No competing interests were disclosed.
Alongside their report, reviewers assign a status to the article:
Invited Reviewers | |||
---|---|---|---|
1 | 2 | 3 | |
Version 1 01 Dec 16 |
read | read | read |
Provide sufficient details of any financial or non-financial competing interests to enable users to assess whether your comments might lead a reasonable person to question your impartiality. Consider the following examples, but note that this is not an exhaustive list:
Sign up for content alerts and receive a weekly or monthly email with all newly published articles
Already registered? Sign in
The email address should be the one you originally registered with F1000.
You registered with F1000 via Google, so we cannot reset your password.
To sign in, please click here.
If you still need help with your Google account password, please click here.
You registered with F1000 via Facebook, so we cannot reset your password.
To sign in, please click here.
If you still need help with your Facebook account password, please click here.
If your email address is registered with us, we will email you instructions to reset your password.
If you think you should have received this email but it has not arrived, please check your spam filters and/or contact for further assistance.
Comments on this article Comments (0)