An external measure compares a clustering with classes chosen by people, and each answers a narrower question than whether the clustering is good. On the textbook's seventeen documents in three classes and three clusters (Manning, Raghavan, and Schütze, 2008, §16.3), purity is 0.706, normalized mutual information $\mathrm{NMI} = I(\Omega; C)/\tfrac{1}{2}[H(\Omega) + H(C)]$ is 0.365, the Rand index 0.676, $F_1$ 0.476 and $F_5$ 0.456. Purity and mutual information are largest with one document per cluster. NMI, proved here to lie between 0 and 1 and equal to the V-measure with $\beta = 1$, penalizes fragmentation without removing the reward. The internal silhouette ranks two k-means clusterings of six points as RSS does (0.614 against 0.425). On Reuters, one k-means clustering has purity 0.744 and NMI 0.382 without conflict.
The lowest-RSS k-means clustering of the six-category Reuters collection put 74.4 percent of the stories in a cluster dominated by their own category. By another measure, normalized mutual information, it scored only 0.38 out of 1. Is it a good clustering or not? Neither number settles it, because the two answer different questions. Purity says that most clusters are dominated by one category. NMI says that the clusters reveal little about which category a story belongs to. Both are true of this clustering, and no single measure decides whether a clustering is good.
A classifier can be checked against the right answers. A clustering, by definition, has none: it was asked to find groups no one specified. Judging one therefore means deciding what "good" should mean, and the main choices give different answers. A clustering evaluation measure turns one of those choices into a number.
Here is the route. First we separate internal from external criteria, and work one internal measure, the silhouette, on the six points of K-means. Then we work each standard external measure on the seventeen-document example of Manning, Raghavan, and Schütze (2008, §16.3), recomputed here. Finally we return to the two Reuters numbers and solve three problems in full. This article is the unit's home for these measures. Clustering measures corrected for chance continues with the adjusted Rand index and adjusted mutual information, with clusterings that should score badly, and with Reuters for 2 to 50 clusters.
Internal and external criteria
An internal criterion scores a clustering by its own geometry: how similar documents are within clusters and how dissimilar across them. The residual sum of squares that k-means minimizes is one. Internal criteria need no labels, but a high score does not mean the clustering is useful. A clustering can be tight and well separated along a dimension no one cares about. Internal criteria also favor whichever algorithm optimizes them, so they cannot fairly compare algorithms.
An external criterion compares the clustering with a set of classes chosen by people, such as the categories of a labeled collection. This measures what usually matters, whether the clusters correspond to distinctions people make. But it requires labels, and it assumes that the given classes are the right answer. As K-means in practice shows on Reuters, an algorithm can find coherent groups that simply differ from the editors' categories.
A third option, the most direct, is to measure the clustering's effect on a task, such as how much faster users find relevant documents when results are clustered. This is the most informative and the most expensive.
The next section works one internal measure. The rest of the article covers external criteria. For those, only the grouping given by the classes matters, not their names: an external measure compares two partitions of the same documents.
The silhouette
RSS cannot compare clusterings with different numbers of clusters. Splitting one document off from a cluster never raises RSS. The document split off then costs nothing, and the rest are measured from their own mean, which minimizes their sum of squares, as K-means proves. With every document as its own centroid, RSS is 0. The silhouette (Rousseeuw, 1987) is an internal measure built to allow that comparison. Here is the idea in one sentence: for each document, compare how far it is from the rest of its own cluster with how far it is from the nearest other cluster.
Take a document $i$ in a cluster that has at least one other member, and a distance between documents. Define
- $a(i)$, the mean distance from $i$ to the other members of its own cluster;
- $b(i)$, the smallest value, over the other clusters, of the mean distance from $i$ to the members of that cluster.
The silhouette of the document is
$$s(i) = \frac{b(i) - a(i)}{\max\{a(i),\, b(i)\}}.$$
A document alone in its cluster is given $s(i) = 0$, Rousseeuw's convention, which he calls arbitrary but the most neutral choice. Since $a(i)$ and $b(i)$ are not negative, their difference is at most the larger of them in absolute value, so $-1 \le s(i) \le 1$. A value near 1 means the document is much nearer its own cluster than any other. A negative value means that it is, on average, nearer the members of some other cluster than those of its own.
The mean of $s(i)$ over all documents scores the whole clustering. Rousseeuw calls it the overall average silhouette width; it is often reported as the silhouette coefficient or silhouette score. He suggests, as one way to choose the number of clusters, taking the number that makes it largest.
The six points. The worked example of K-means has six points: $A = (1, 1)$, $B = (1.5, 2)$, $C = (3, 4)$, $D = (5, 7)$, $E = (3.5, 5)$ and $F = (4.5, 5)$. That article found two clusterings at which k-means stops: $\{A, B\}, \{C, D, E, F\}$ with RSS 7.875, the optimum, and $\{A, B, C\}, \{D, E, F\}$ with RSS 10.67. We use Euclidean distance (not squared), rounded to three decimals.
In the first clustering, $A$ has one companion, so $a(A)$ is the distance from $A$ to $B$, $\sqrt{0.5^2 + 1^2} = 1.118$. Its distances to $C$, $D$, $E$ and $F$ are 3.606, 7.211, 4.717 and 5.315, with mean $b(A) = 5.212$. So $s(A) = (5.212 - 1.118)/5.212 = 0.785$.
Point $C$ is the interesting one. Its distances to $D$, $E$ and $F$ are 3.606, 1.118 and 1.803, with mean 2.175. Its distances to $A$ and $B$ are 3.606 and 2.5, with mean 3.053. In the first clustering $a(C) = 2.175$ and $b(C) = 3.053$, so $s(C) = (3.053 - 2.175)/3.053 = 0.287$. In the second clustering the two means exchange roles, and $s(C) = (2.175 - 3.053)/3.053 = -0.287$. Placed with $A$ and $B$, point $C$ is on average nearer the other cluster's members than its own.
| Point | $a$, first | $b$, first | $s$, first | $a$, second | $b$, second | $s$, second |
|---|---|---|---|---|---|---|
| $A$ | 1.118 | 5.212 | 0.785 | 2.362 | 5.748 | 0.589 |
| $B$ | 1.118 | 4.113 | 0.728 | 1.809 | 4.650 | 0.611 |
| $C$ | 2.175 | 3.053 | 0.287 | 3.053 | 2.175 | −0.287 |
| $D$ | 2.722 | 6.657 | 0.591 | 2.281 | 5.640 | 0.596 |
| $E$ | 1.539 | 4.161 | 0.630 | 1.750 | 3.147 | 0.444 |
| $F$ | 1.621 | 4.779 | 0.661 | 1.531 | 3.787 | 0.596 |
| Mean | 0.614 | 0.425 |
The mean silhouette is 0.614 for the first clustering and 0.425 for the second. On these six points it ranks the two clusterings as RSS does, and it also names the misplaced point, which RSS does not. That agreement is an observation about these two clusterings, not a general fact. The same six points give a pair on which the measures disagree. The clustering $\{A, B, E\}, \{C, D, F\}$ has RSS 19.0 and mean silhouette 0.180. The clustering $\{A\}, \{B, C, D, E, F\}$ has a higher RSS, 20.7, and also a higher mean silhouette, 0.215. RSS prefers the first and the silhouette the second.
The silhouette shares the limits of every internal criterion stated above. It rewards compact, well-separated groups whether or not anyone cares about the distinction they draw. It also needs the distance between every pair of documents, so its cost grows with the square of the collection size. The Reuters experiments in this unit were not scored with it.
The Davies–Bouldin index (Davies and Bouldin, 1979) is another internal measure. For each cluster it takes the largest ratio, over the other clusters, of the two clusters' combined scatter to the distance between their centroids; it averages these ratios, so lower is better.
The worked example
Seventeen documents from three classes, which the textbook draws as x, o, and ◇ in its Figure 16.4, are grouped into three clusters:
As a contingency table, with one row per cluster, one column per class, and the totals on the margins:
| Cluster | x | o | ◇ | Cluster size |
|---|---|---|---|---|
| 1 | 5 | 1 | 0 | 6 |
| 2 | 1 | 4 | 1 | 6 |
| 3 | 2 | 0 | 3 | 5 |
| Class size | 8 | 5 | 4 | 17 |
Every measure below is a function of this table alone. Write $n_{kj}$ for the entry in row $k$ and column $j$, $n_k$ for the size of cluster $k$, $n_j$ for the size of class $j$, and $N = 17$ for the total.
Purity
Purity assigns each cluster to its most frequent class and counts the fraction of documents that match their cluster's class:
$$\mathrm{purity}(\Omega, C) = \frac{1}{N} \sum_k \max_j \lvert \omega_k \cap c_j \rvert,$$
where $\Omega = \{\omega_1, \dots, \omega_K\}$ are the clusters and $C = \{c_1, \dots, c_J\}$ the classes. In the example the row maxima are 5, 4, and 3, so purity is $12/17 \approx 0.71$. It is the accuracy a classifier would have if it labeled every document with its cluster's majority class.
Purity is easy to understand and has one serious flaw: it rewards many clusters. Splitting a cluster never lowers purity, because the majority count of the whole is at most the sum of the majority counts of the parts: $\max_j (a_j + b_j) \le \max_j a_j + \max_j b_j$. With one document per cluster, every cluster is pure, and purity is 1. Purity can only compare clusterings with the same number of clusters.
Normalized mutual information
Purity looks only at each cluster's majority. Mutual information uses the whole table to measure how much a document's cluster reveals about its class:
$$I(\Omega; C) = \sum_k \sum_j \frac{n_{kj}}{N} \log \frac{N\, n_{kj}}{n_k\, n_j}.$$
Each term compares how often cluster $k$ and class $j$ occur together, $n_{kj}/N$, with how often they would if clusters and classes were independent, $(n_k/N)(n_j/N)$. Where they co-occur more than independence predicts, the logarithm is positive. It is the same quantity used for feature selection, which defines it; here it is measured between clusters and classes rather than terms and classes.
In the example, with natural logarithms and rounded to four decimals, the seven nonzero cells contribute:
| Cell | $n_{kj}/N$ | $\log \dfrac{N n_{kj}}{n_k n_j}$ | Term |
|---|---|---|---|
| cluster 1, x | 5/17 | ln(85/48) = 0.5715 | 0.1681 |
| cluster 1, o | 1/17 | ln(17/30) = −0.5680 | −0.0334 |
| cluster 2, x | 1/17 | ln(17/48) = −1.0380 | −0.0611 |
| cluster 2, o | 4/17 | ln(68/30) = 0.8183 | 0.1925 |
| cluster 2, ◇ | 1/17 | ln(17/24) = −0.3448 | −0.0203 |
| cluster 3, x | 2/17 | ln(34/40) = −0.1625 | −0.0191 |
| cluster 3, ◇ | 3/17 | ln(51/20) = 0.9361 | 0.1652 |
The majority cells add information and the stray documents subtract a little, for a total of $I = 0.3919$ nats.
Mutual information as a drop in entropy. $I$ is never negative, and it is at most the entropy of the classes and at most the entropy of the clusters. The proof rewrites it, and the plan is this: $I$ is the uncertainty about a document's class, minus the uncertainty that remains once its cluster is known. The entropy of the classes measures the first, and the conditional entropy of the classes given the clusters measures the second:
$$H(C) = -\sum_j \frac{n_j}{N} \log \frac{n_j}{N}, \qquad H(C \mid \Omega) = -\sum_k \sum_j \frac{n_{kj}}{N} \log \frac{n_{kj}}{n_k}.$$
Empty cells contribute nothing to either sum. Split the logarithm in the definition of $I$ as $\log \frac{N n_{kj}}{n_k n_j} = \log \frac{n_{kj}}{n_k} - \log \frac{n_j}{N}$. Then
$$I(\Omega; C) = \sum_k \sum_j \frac{n_{kj}}{N} \log \frac{n_{kj}}{n_k} - \sum_j \Big( \sum_k \frac{n_{kj}}{N} \Big) \log \frac{n_j}{N} = -H(C \mid \Omega) + H(C),$$
because the entries of column $j$ add up to $n_j$. Every term of $H(C \mid \Omega)$ is zero or positive, since $n_{kj} \le n_k$ makes each logarithm zero or negative. So
$$I(\Omega; C) = H(C) - H(C \mid \Omega) \le H(C).$$
Splitting the logarithm the other way, as $\log \frac{n_{kj}}{n_j} - \log \frac{n_k}{N}$, and using the fact that the entries of row $k$ add up to $n_k$, gives the mirror image:
$$I(\Omega; C) = H(\Omega) - H(\Omega \mid C) \le H(\Omega), \qquad H(\Omega) = -\sum_k \frac{n_k}{N} \log \frac{n_k}{N}, \quad H(\Omega \mid C) = -\sum_k \sum_j \frac{n_{kj}}{N} \log \frac{n_{kj}}{n_j},$$
where $H(\Omega \mid C) \ge 0$ because $n_{kj} \le n_j$.
$I$ is also never negative. The inequality $\log x \le x - 1$ holds for every $x > 0$, with equality only at $x = 1$. Apply it to each nonempty cell with $x = n_k n_j / (N n_{kj})$:
$$-I(\Omega; C) = \sum_{n_{kj} > 0} \frac{n_{kj}}{N} \log \frac{n_k n_j}{N n_{kj}} \le \sum_{n_{kj} > 0} \Big( \frac{n_k n_j}{N^2} - \frac{n_{kj}}{N} \Big) \le \sum_k \sum_j \frac{n_k n_j}{N^2} - 1 = 0.$$
The last step adds the empty cells' terms $n_k n_j / N^2$ and uses $\sum_k n_k = \sum_j n_j = N$. Both inequalities are equalities exactly when every cell has $n_{kj} = n_k n_j / N$, the count that independence predicts. So $I = 0$ exactly when the clusters carry no information about the classes.
The entropies in the example are
$$H(\Omega) = -2 \cdot \tfrac{6}{17} \ln \tfrac{6}{17} - \tfrac{5}{17} \ln \tfrac{5}{17} = 1.0951, \qquad H(C) = -\tfrac{8}{17} \ln \tfrac{8}{17} - \tfrac{5}{17} \ln \tfrac{5}{17} - \tfrac{4}{17} \ln \tfrac{4}{17} = 1.0551.$$
The conditional entropies are $H(C \mid \Omega) = 0.6632$ and $H(\Omega \mid C) = 0.7031$, and indeed $1.0551 - 0.6632 = 1.0951 - 0.7031 = 0.3919$ (the second difference is 0.3920 from the rounded figures). Knowing the cluster removes 0.3919 of the 1.0551 nats of uncertainty about the class.
Singletons maximize it. Like purity, mutual information reaches its maximum with one document per cluster. Each singleton cluster lies inside one class, so its one nonempty cell has $n_{kj} = n_k = 1$ and contributes $\log 1 = 0$ to $H(C \mid \Omega)$. Hence $H(C \mid \Omega) = 0$ and $I = H(C)$, the upper bound just proved. Knowing a document's singleton cluster tells everything about its class. The same holds for any clustering in which every cluster lies inside one class. Mutual Information proves the general statements behind this section, and that merging clusters can never raise the mutual information with the classes (its data processing inequality); Entropy is the site's home for entropy and conditional entropy.
Normalized mutual information divides by the average entropy of the clusters and the classes:
$$\mathrm{NMI}(\Omega, C) = \frac{I(\Omega; C)}{[H(\Omega) + H(C)]/2}.$$
In the example NMI is $0.3919 / 1.0751 = 0.365$, the 0.36 of the textbook's Table 16.2. The base of the logarithm cancels in the ratio.
Splitting a cluster never lowers $H(\Omega)$. If a cluster of $n$ documents is split into parts of $a$ and $b$, its term $-\frac{n}{N}\log\frac{n}{N}$ is replaced by $-\frac{a}{N}\log\frac{a}{N} - \frac{b}{N}\log\frac{b}{N}$, which is larger by $\frac{n}{N}\big[-\frac{a}{n}\log\frac{a}{n} - \frac{b}{n}\log\frac{b}{n}\big] \ge 0$. Every clustering can be split step by step into singletons, so the singletons have the largest entropy. For them each of the $N$ clusters has $n_k/N = 1/N$, so $H(\Omega) = -N \cdot \frac{1}{N} \log \frac{1}{N} = \log N$. The entropy need not grow with the number of clusters: three clusters of 15, 1 and 1 documents have entropy 0.444, lower than the 0.691 of two clusters of 9 and 8. So the denominator penalizes fragmentation.
NMI ranges from 0 to 1. It is 0 exactly when $I = 0$, that is, when the clusters carry no information about the classes. For the upper end, $I \le H(\Omega)$ and $I \le H(C)$ were proved above. A number that is at most each of two others is at most their mean, so $I \le [H(\Omega) + H(C)]/2$ and NMI is at most 1. The course text states this bound, calling it a tight upper bound, and leaves its proof as Exercise 16.8. The two lines above are that proof. NMI equals 1 exactly when $I = H(\Omega) = H(C)$, that is, when both conditional entropies are 0. $H(C \mid \Omega) = 0$ means every cluster lies inside one class, and $H(\Omega \mid C) = 0$ means every class lies inside one cluster. Together they say that the clusters are the classes. (NMI is undefined in the one case where both entropies are 0, a single cluster and a single class.)
Other normalizations are also used, such as the geometric mean of the two entropies (Strehl and Ghosh, 2002, equation 2). So NMI values from different sources are not always comparable. (In this example the two normalizations agree to three decimals.)
Homogeneity, completeness and the V-measure
NMI is one number, and a clustering can fall short of the classes in two different ways. Its clusters can mix classes, or its classes can be spread over several clusters. Rosenberg and Hirschberg (2007) score the two separately, using the two conditional entropies of the previous section.
Homogeneity is the fraction of the class uncertainty that the clusters remove:
$$h = 1 - \frac{H(C \mid \Omega)}{H(C)} = \frac{I(\Omega; C)}{H(C)}.$$
It is 1 exactly when every cluster lies inside one class. Completeness exchanges the roles:
$$c = 1 - \frac{H(\Omega \mid C)}{H(\Omega)} = \frac{I(\Omega; C)}{H(\Omega)},$$
and it is 1 exactly when every class lies inside one cluster. The second form of each follows from $I = H(C) - H(C \mid \Omega) = H(\Omega) - H(\Omega \mid C)$. By the bounds $0 \le I \le H(C)$ and $I \le H(\Omega)$, both lie between 0 and 1. Two conventions cover the cases where a denominator is 0: $h = 1$ when there is a single class, and $c = 1$ when there is a single cluster.
The V-measure is their weighted harmonic mean,
$$V_\beta = \frac{(1 + \beta)\, h\, c}{\beta h + c},$$
where $\beta > 1$ weights completeness more and $\beta < 1$ weights homogeneity more.
The V-measure with $\beta = 1$ is this article's NMI. Substitute $h = I/H(C)$ and $c = I/H(\Omega)$, assuming neither entropy is 0, and multiply the numerator and denominator by $H(\Omega) H(C) / I$:
$$V_\beta = \frac{(1 + \beta)\, I^2 / [H(C) H(\Omega)]}{\beta I / H(C) + I / H(\Omega)} = \frac{(1 + \beta)\, I}{\beta H(\Omega) + H(C)}, \qquad V_1 = \frac{2I}{H(\Omega) + H(C)} = \mathrm{NMI}(\Omega, C).$$
So $V_1$ is exactly NMI normalized by the arithmetic mean of the entropies, the normalization of the course text and of this article. It is not the NMI of Strehl and Ghosh: dividing by the geometric mean gives $I / \sqrt{H(\Omega) H(C)} = \sqrt{h c}$, the geometric mean of homogeneity and completeness, not their harmonic mean.
In the example, $h = 0.3919/1.0551 = 0.3715$ and $c = 0.3919/1.0951 = 0.3579$, and $V_1 = 2 \times 0.3715 \times 0.3579 / (0.3715 + 0.3579) = 0.365$, the NMI. The clustering fails about equally in both directions.
Example (the two degenerate clusterings). One document per cluster is perfectly homogeneous and far from complete; one cluster for everything is the reverse. For the singletons of the seventeen documents, $h = 1$ and $c = H(C)/\log N = 1.0551/2.8332 = 0.3724$, so $V_1 = 2c/(1 + c) = 0.7448/1.3724 = 0.543$. For a single cluster, $I = 0$ gives $h = 0$; $c = 1$ by the convention, and $V_1 = 0$. The pair $(h, c)$ says which way a clustering fails. NMI alone does not.
The V-measure is the score reported for clustering tasks in the Massive Text Embedding Benchmark for embedding models, where it grades a k-means clustering of the embedded texts against their labels (Muennighoff, Tazi, Magne, and Reimers, 2023, §3.2). Evaluating embedding models describes the benchmark and what its scores do not measure.
The Rand index
A third view looks at pairs. The Rand index (Rand, 1971) treats clustering as a series of decisions about pairs of documents. Each of the $\binom{N}{2}$ pairs is either put in the same cluster or not, and either belongs to the same class or not. These are the four cells that evaluating classifiers uses, with pairs of documents in place of documents:
| Same class | Different classes | |
|---|---|---|
| Same cluster | true positive (TP) | false positive (FP) |
| Different clusters | false negative (FN) | true negative (TN) |
The Rand index is the fraction of pair decisions that are correct:
$$\mathrm{RI} = \frac{TP + TN}{TP + FP + FN + TN}.$$
The four counts come from the contingency table by counting pairs, $\binom{n}{2} = n(n-1)/2$ for a group of $n$:
- All pairs. The 17 documents form $\binom{17}{2} = 136$ pairs.
- Same cluster (TP + FP): pairs inside a row's total, $\binom{6}{2} + \binom{6}{2} + \binom{5}{2} = 15 + 15 + 10 = 40$.
- Same cluster and same class (TP): pairs inside a single cell, $\binom{5}{2} + \binom{4}{2} + \binom{3}{2} + \binom{2}{2} = 10 + 6 + 3 + 1 = 20$. Cells of 1 contribute no pairs. So FP $= 40 - 20 = 20$.
- Same class (TP + FN): pairs inside a column's total, $\binom{8}{2} + \binom{5}{2} + \binom{4}{2} = 28 + 10 + 6 = 44$. So FN $= 44 - 20 = 24$.
- The rest are true negatives: TN $= 136 - 20 - 20 - 24 = 72$.
The Rand index is $(20 + 72)/136 \approx 0.68$.
Most pairs in a collection with several classes belong to different classes, so true negatives dominate and the Rand index tends to be high even for poor clusterings.
Example (all seventeen documents in one cluster). The Rand index of the single cluster is $44/136 = 0.324$, with TP = 44, FP = 92 and FN = TN = 0. Every pair is now a same-cluster pair. All 44 same-class pairs become true positives and the other 92 pairs false positives, with no negatives at all. Lumping loses the 72 true negatives that carried most of the example's score.
The F measure
When one kind of pair error matters more than the other, the pair counts also give precision and recall:
- $P = TP/(TP + FP)$, the fraction of same-cluster pairs that are same-class;
- $R = TP/(TP + FN)$, the fraction of same-class pairs that were put together.
In the example, $P = 20/40 = 0.5$ and $R = 20/44 \approx 0.455$, so
$$F_1 = \frac{2PR}{P + R} = \frac{2 \times 0.5 \times 0.455}{0.955} \approx 0.48.$$
The F measure lets an evaluator weigh the two kinds of error. Separating similar documents is a false negative; grouping dissimilar ones is a false positive. The general form is $F_\beta = (\beta^2 + 1)PR/(\beta^2 P + R)$, where $\beta > 1$ weights recall more heavily, as precision and recall explains. Here that means penalizing false negatives more. With $\beta = 5$ the example scores $F_5 = 26 \times 0.5 \times 0.455 / (25 \times 0.5 + 0.455) \approx 0.46$, close to its recall. These are the textbook's own values for this example.
Correcting for chance
The Rand index and mutual information both give credit for agreement that would happen by chance. The adjusted Rand index (ARI) and adjusted mutual information (AMI) subtract what a random clustering with the same cluster sizes would score. Their expected value is 0 for such a clustering, and they are 1 when the clusters are the classes. For the example the ARI is 0.243 and the AMI is 0.260. Clustering measures corrected for chance derives both, and shows what every measure of this article makes of singletons, of a single cluster and of random clusterings.
Back to Reuters
Back to the two numbers we started with. On the six-category Reuters collection in K-means in practice, ten random-start k-means runs with $K = 6$ gave purity from 0.703 to 0.803 and NMI from 0.372 to 0.496. Over the same runs the Rand index stayed between 0.659 and 0.721.
The lowest-RSS clustering found with k-means++ split the large earn category into four clusters. It put nearly all of three small categories, and three quarters of a fourth, into one. Its purity was 0.744, because most clusters are dominated by one category. Its NMI was only 0.382, because the clusters say little about which of the small categories a story belongs to. So the two numbers from the opening do not conflict: they answer different questions.
Worked problems
Problems 1, 2 and 3 are Exercises 16.3, 16.7 and 16.9 of the course text (Manning, Raghavan, and Schütze, 2008). The statements are in our own words; the script eval_worked.py checks every number.
Problem 1 (doubling the collection). Replace every document of the seventeen-document example by two identical copies of itself, in the same class and the same cluster. (i) Is the set of 34 documents less difficult, equally difficult or more difficult to cluster than the 17? (ii) Compute purity, NMI, the Rand index and $F_5$ for the 34 documents, and say which change. (iii) Which measures are best suited to compare the quality of the two clusterings?
Solution. (i) Equally difficult. The 34 documents occupy the same 17 positions, two at each. Every distance between positions is unchanged, and two copies at one position are at the same distance from everything, so no distance-based rule has a reason to separate them. The task is the original one with every document counted twice.
(ii) Every entry of the contingency table doubles, and $N = 34$:
| Cluster | x | o | ◇ | Cluster size |
|---|---|---|---|---|
| 1 | 10 | 2 | 0 | 12 |
| 2 | 2 | 8 | 2 | 12 |
| 3 | 4 | 0 | 6 | 10 |
| Class size | 16 | 10 | 8 | 34 |
Purity. The row maxima are 10, 8 and 6, so purity is $24/34 = 0.706$, unchanged from $12/17$.
NMI. Each term of the mutual information is $\frac{2n_{kj}}{2N} \log \frac{2N \cdot 2n_{kj}}{2n_k \cdot 2n_j}$. The factors of 2 cancel inside and outside the logarithm, so every term is unchanged and $I = 0.3919$. The entropies depend only on the proportions $n_k/N$ and $n_j/N$, which are also unchanged. So NMI is still $0.365$.
Pair counts. There are $\binom{34}{2} = 561$ pairs.
- Same cluster: $\binom{12}{2} + \binom{12}{2} + \binom{10}{2} = 66 + 66 + 45 = 177$.
- True positives, pairs inside one cell: the cells 10, 8, 6 and 4 give $45 + 28 + 15 + 6 = 94$, and the three cells of 2 give one pair each, so TP $= 97$. Hence FP $= 177 - 97 = 80$.
- Same class: $\binom{16}{2} + \binom{10}{2} + \binom{8}{2} = 120 + 45 + 28 = 193$, so FN $= 193 - 97 = 96$.
- TN $= 561 - 97 - 80 - 96 = 288$.
There is a pattern behind these counts. Each pair of original documents becomes four pairs of copies with the same status, which multiplies 20, 20, 24 and 72 by four: 80, 80, 96 and 288. The 17 pairs formed by a document and its own copy are new, and all are true positives: $80 + 17 = 97$.
Rand index. $(97 + 288)/561 = 385/561 = 0.686$, up from 0.676.
$F_5$. Precision is $97/177 = 0.5480$, up from 0.5, and recall is $97/193 = 0.5026$, up from 0.4545. So $F_5 = 26 \times 0.5480 \times 0.5026 / (25 \times 0.5480 + 0.5026) = 0.504$, up from 0.456.
Purity and NMI stay the same. The Rand index and $F_5$ increase.
(iii) Purity and NMI. By (i) the two clusterings are equally good, and only these two measures say so. They depend on the table only through proportions. The pair-counting measures rise because of the 17 copy pairs. These are true positives in every clustering that keeps the two copies of a document together, so the rise reflects the duplication, not the quality.
The chance-adjusted measures change as well, and Clustering measures corrected for chance says by how much and why.
Problem 2 (subdividing a perfect clustering). Let $\Omega$ be a clustering whose clusters are exactly the classes $C$, and let $\Omega'$ be obtained by dividing some clusters of $\Omega$ into smaller ones. Show that $I(\Omega; C) = I(\Omega'; C)$.
Solution. Both equal $H(C)$. The NMI section showed that $I = H(C) - H(C \mid \Omega)$, and that $H(C \mid \Omega) = 0$ whenever every cluster lies inside one class. For then each cluster $k$ has a single nonempty cell, with $n_{kj} = n_k$, and its term $-\frac{n_{kj}}{N} \log \frac{n_{kj}}{n_k}$ is 0. Every cluster of $\Omega$ is a class, so $I(\Omega; C) = H(C)$. Every cluster of $\Omega'$ is part of a cluster of $\Omega$, hence part of one class, so $I(\Omega'; C) = H(C)$ as well.
To see it in numbers, take the seventeen documents with their classes of 8, 5 and 4 as the clusters. Then $I = H(C) = 1.0551$ and NMI is 1. Now divide the x cluster into clusters of 5 and 3. The mutual information is still 1.0551, and purity is still 1. But $H(\Omega')$ rises from 1.0551 to 1.3664, so NMI falls to $1.0551 / \tfrac{1}{2}(1.3664 + 1.0551) = 0.871$. The split turns the $5 \times 3 = 15$ pairs between the two parts into false negatives, so the Rand index falls from 1 to $(29 + 92)/136 = 0.890$, and the ARI from 1 to 0.723. This is the reason for normalizing: mutual information, like purity, cannot tell a perfect clustering from a needlessly fine one.
Problem 3 (exchanging clusters and classes). Mutual information is symmetric: exchanging the roles of clusters and classes leaves $I(\Omega; C)$ unchanged. Which of purity, the Rand index and the F measure are symmetric in the same sense?
Solution. The Rand index and $F_1$ are symmetric. Purity is not, and neither is $F_\beta$ for $\beta \ne 1$. Exchanging the roles turns the rows of the contingency table into its columns.
Purity takes the largest entry of each row; after the exchange it takes the largest entry of each column, a different quantity. With all seventeen documents in one cluster, purity is $8/17 = 0.471$. Exchange the roles: the three classes become three clusters, and the single cluster becomes a single class that contains everything. Every cluster is then pure, and purity is 1. (For the example's own table the two values happen to agree, because the column maxima are also 5, 4 and 3.)
The Rand index. A pair is a true positive if its documents share both a cluster and a class, and a true negative if they share neither. Both conditions treat clusters and classes alike, so TP and TN are unchanged. FP and FN exchange: in the example they become 24 and 20. The Rand index uses only $TP + TN$ and the total, so it is symmetric.
The F measure. Since FP and FN exchange, so do precision and recall. $F_1 = 2PR/(P + R)$ is unchanged by that. For $\beta \ne 1$, $F_\beta = (\beta^2 + 1)PR/(\beta^2 P + R)$ weights the two differently and changes unless $P = R$. In the example the exchange gives $P = 0.455$ and $R = 0.5$, and $F_5 = 26 \times 0.455 \times 0.5/(25 \times 0.455 + 0.5) = 0.498$ in place of 0.456.
Of the article's other measures, NMI, the ARI and the AMI are symmetric, because their formulas treat the rows and the columns alike. Homogeneity and completeness exchange with each other, so $V_1$ is symmetric and $V_\beta$ for $\beta \ne 1$ is not.
What we have learned
Without a right answer, a clustering is judged against classes chosen by people, and each external measure answers a narrower question than "is it good". On Reuters a purity of 0.744 and an NMI of 0.382 described the same clustering without conflict. Purity and mutual information reward splitting, the Rand index is inflated by true negatives, and normalization only reduces the reward for fragmentation. The two measures that subtract what chance would give, the adjusted Rand index and adjusted mutual information, are the subject of Clustering measures corrected for chance, which also tests every measure on degenerate and random clusterings and on Reuters as $K$ grows. Among internal measures, the silhouette scores a clustering from distances alone and can compare different numbers of clusters. The table collects the external measures.
| Measure | Range | Rewards more clusters? | Example value |
|---|---|---|---|
| Purity | 0 to 1 | Yes, reaching 1 at one document per cluster | 0.71 |
| NMI (the V-measure with β = 1) | 0 to 1 | Less than purity: the normalization penalizes fragmentation, but singletons can still outscore a sensible clustering | 0.36 |
| Homogeneity and completeness | 0 to 1 each | Homogeneity yes, reaching 1 at one document per cluster; completeness the reverse, reaching 1 at a single cluster | 0.37 and 0.36 |
| Rand index | 0 to 1 | Not directly, but inflated by the many true negatives | 0.68 |
| Adjusted Rand index | expected value 0 for chance, up to 1 | No: degenerate clusterings score 0 and random ones about 0 | 0.24 |
| Adjusted mutual information | expected value 0 for chance, up to 1 | No: degenerate clusterings score 0 and random ones about 0 | 0.26 |
| F measure | 0 to 1 | Adjustable through β; large β rewards fewer clusters | $F_1$ 0.48, $F_5$ 0.46 |
Clustering measures corrected for chance comes next and derives the last two rows of the table. After it, hierarchical clustering leaves flat clusterings with $K$ fixed in advance and builds a tree, broad groups dividing into narrower ones, and compares it with k-means on Reuters.
The scripts that recompute the example are tools/experiments/clustering/textbook_eval.py and tools/experiments/clustering/eval_worked.py in the site repository; the Reuters measures come from the Reuters scripts in the same folder.
References
- Davies, D. L., and Bouldin, D. W. (1979). A cluster separation measure. IEEE Transactions on Pattern Analysis and Machine Intelligence, PAMI-1(2), 224–227. record
- Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, section 16.3. Cambridge University Press. record · 102 pages
- Muennighoff, N., Tazi, N., Magne, L., and Reimers, N. (2023). MTEB: Massive text embedding benchmark. In Proceedings of the 17th Conference of the European Chapter of the Association for Computational Linguistics, 2014–2037. record · 3 pages
- Rand, W. M. (1971). Objective criteria for the evaluation of clustering methods. Journal of the American Statistical Association, 66(336), 846–850. record
- Rosenberg, A., and Hirschberg, J. (2007). V-measure: A conditional entropy-based external cluster evaluation measure. Proceedings of the 2007 Joint Conference on Empirical Methods in Natural Language Processing and Computational Natural Language Learning (EMNLP-CoNLL), 410–420. record
- Rousseeuw, P. J. (1987). Silhouettes: A graphical aid to the interpretation and validation of cluster analysis. Journal of Computational and Applied Mathematics, 20, 53–65. record · 2 pages
- Strehl, A., and Ghosh, J. (2002). Cluster ensembles: A knowledge reuse framework for combining multiple partitions. Journal of Machine Learning Research, 3, 583–617. record
Reviewed: verified, 16 Nov 2026 · checked against sources, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 14 revisions