Calinski-Harabasz Index Calculator
Inputs
- Inputs: between-cluster dispersion (trace of B) 1,450.00, within-cluster dispersion (trace of W) 620.00, 4 clusters and 300 points.
- Between-cluster dispersion per degree of freedom: 1,450.00 / (4 - 1) = 483.33.
- Within-cluster dispersion per degree of freedom: 620.00 / (300 - 4) = 2.0946.
- Calinski-Harabasz index = 483.33 / 2.0946 = 230.75: higher values mean denser, better separated clusters.
The Calinski-Harabasz index, published in 1974 and also called the variance ratio criterion, scores a clustering the way an analysis of variance scores a grouping: it asks whether the clusters are far apart relative to how spread out they are inside. Enter the trace of the between-cluster dispersion matrix, the trace of the within-cluster dispersion matrix, the number of clusters k and the number of points n, and the calculator returns the index with both per-degree-of-freedom components.
Unlike indices that inspect individual points or extreme pairs, this one works from two summary traces, so it can be computed from the output of any centroid-based clustering that reports its sums of squares.
Worked examples
Four clusters, 300 points
(1450 · 620 · 4 · 300)
| Calinski-Harabasz index | 230.75 |
| Between-cluster dispersion per df | 483.33 |
| Within-cluster dispersion per df | 2.0946 |
Three tighter clusters
(860 · 410 · 3 · 180)
| Calinski-Harabasz index | 185.63 |
| Between-cluster dispersion per df | 430.00 |
| Within-cluster dispersion per df | 2.3164 |
Six clusters, 520 points
(2300 · 1500 · 6 · 520)
| Calinski-Harabasz index | 157.63 |
| Between-cluster dispersion per df | 460.00 |
| Within-cluster dispersion per df | 2.9183 |
Dispersion traces: the two sums of squares
The between-cluster dispersion trace, written tr(B), totals the squared distances of the cluster centroids from the grand centroid, weighted by cluster size. It is large when the centroids sit far from the centre of the data. The within-cluster dispersion trace, tr(W), totals the squared distances of the points from their own centroids, and it is large when the clusters are loose and sprawling.
A good clustering wants the first number big and the second small, but the raw ratio of the two traces is not yet a fair score, because splitting data into more clusters mechanically inflates tr(B) and deflates tr(W). The degrees-of-freedom scaling in the next section is what corrects for that.
- tr(B): between-cluster dispersion - how far the centroids are from the grand centroid.
- tr(W): within-cluster dispersion - how far points are from their own centroids.
- Both traces come straight from the sums of squares a k-means run already computes.
The degrees-of-freedom correction
The index divides tr(B) by k - 1 and tr(W) by n - k before taking the ratio, exactly the mean-square construction of an F-statistic. In the first worked example, tr(B) = 1,450 over 4 - 1 = 3 degrees of freedom gives 483.33 per degree of freedom, and tr(W) = 620 over 300 - 4 degrees of freedom gives 2.0946. The index is the ratio, 483.33 / 2.0946 = 230.75.
The correction is what lets the index compare different values of k on the same data. Without it, the score would reward splitting indefinitely; with it, an extra cluster only raises the index if the split genuinely separates mass that was previously pooled.
| Example | tr(B) per df | tr(W) per df | Index |
|---|---|---|---|
| First | 483.33 | 2.0946 | 230.75 |
| Second | 430.00 | 2.3164 | 185.63 |
| Third | 460.00 | 2.9183 | 157.63 |
Worked examples
Example 1: Between-cluster dispersion (trace B) 1450; Within-cluster dispersion (trace W) 620; Number of clusters k 4; Number of points n 300. Calinski-Harabasz index = 230.75. Supporting values: Between-cluster dispersion per df 483.33; Within-cluster dispersion per df 2.0946. Inputs: between-cluster dispersion (trace of B) 1,450.00, within-cluster dispersion (trace of W) 620.00, 4 clusters and 300 points. Between-cluster dispersion per degree of freedom: 1,450.00 / (4 - 1) = 483.33. Within-cluster dispersion per degree of freedom: 620.00 / (300 - 4) = 2.0946. Calinski-Harabasz index = 483.33 / 2.0946 = 230.75: higher values mean denser, better separated clusters.
Example 2: Between-cluster dispersion (trace B) 860; Within-cluster dispersion (trace W) 410; Number of clusters k 3; Number of points n 180. Calinski-Harabasz index = 185.63. Supporting values: Between-cluster dispersion per df 430.00; Within-cluster dispersion per df 2.3164. Inputs: between-cluster dispersion (trace of B) 860.00, within-cluster dispersion (trace of W) 410.00, 3 clusters and 180 points. Between-cluster dispersion per degree of freedom: 860.00 / (3 - 1) = 430.00. Within-cluster dispersion per degree of freedom: 410.00 / (180 - 3) = 2.3164. Calinski-Harabasz index = 430.00 / 2.3164 = 185.63: higher values mean denser, better separated clusters.
Example 3: Between-cluster dispersion (trace B) 2300; Within-cluster dispersion (trace W) 1500; Number of clusters k 6; Number of points n 520. Calinski-Harabasz index = 157.63. Supporting values: Between-cluster dispersion per df 460.00; Within-cluster dispersion per df 2.9183. Inputs: between-cluster dispersion (trace of B) 2,300.00, within-cluster dispersion (trace of W) 1,500.00, 6 clusters and 520 points. Between-cluster dispersion per degree of freedom: 2,300.00 / (6 - 1) = 460.00. Within-cluster dispersion per degree of freedom: 1,500.00 / (520 - 6) = 2.9183. Calinski-Harabasz index = 460.00 / 2.9183 = 157.63: higher values mean denser, better separated clusters.
Comparing cluster counts on the same data
The index has no universal scale and no pass mark. Its only legitimate use is comparative: the same dataset, the same features and scaling, several candidate clusterings, and the highest index wins. The second worked example - 3 clusters over 180 points - scores 185.63, and the six-cluster third example scores 157.63 despite a much larger between trace of 2,300, because its within trace of 1,500 spread over 520 points leaves a per-degree-of-freedom value of 2.9183.
Read as a set, the three examples show why raw dispersion alone misleads: the third example separates the most total mass, yet once the extra clusters and the looser interiors are charged against it, it scores lowest of the three.
Strengths and blind spots
The index is fast, deterministic and available for any clustering that produces centroids, which is why software such as scikit-learn exposes it as a standard score. It tends to agree with the silhouette on well-behaved, roughly spherical clusters, and the two used together - one built from traces, one from per-point distances - make a reasonable cross-check.
Its blind spots follow from the trace construction. Because it measures everything against centroids, it favours round, equally sized clusters and can score a correct but elongated or nested partition poorly. It is also sensitive to feature scaling, since a single large-variance feature dominates both traces. Standardising features before clustering is the usual remedy, and reporting the index alongside a per-point index such as the silhouette is the usual safeguard.
Computing the traces from a clustering
Most k-means implementations report the within-cluster sum of squares directly as the objective or inertia, which is exactly tr(W). The between trace follows from the total sum of squares about the grand centroid: tr(B) = total - tr(W), an identity that holds for any partition of the points. With k and n counted from the same run, the four inputs of this calculator are complete.
One practical note: the traces must come from the final assignment of the same clustering being scored. Mixing the within trace of one run with the between trace of another, or rescoring after reassigning points, produces an index that describes no clustering at all.
A note on provenance helps explain the index's F-statistic flavour: Calinski and Harabasz proposed it in 1974 as a stopping rule for hierarchical clustering, a way to decide where to cut a dendrogram, and the degrees-of-freedom construction was their device for penalising each additional cluster the cut creates. That origin is still visible in the formula's behaviour - it is at its most trustworthy comparing nested or near-nested partitions of one dataset, which is the dendrogram setting, and it should be handled more cautiously when the candidate clusterings come from entirely different algorithms with different biases.
Software implementations occasionally differ in a detail worth checking: some compute the traces from the final centroids after reassignment, others from the assignment that produced the reported objective. On a converged k-means run the two coincide; on an early-stopped run they can differ enough to move the second decimal of the index. The first example's 230.75 is only reproducible if the traces, the cluster count and the point count all describe the same final partition.
A closing caution concerns ties and near-ties. Because the index is a single number with no sampling distribution attached, two clusterings scoring 185.63 and a near-identical value are, for practical purposes, the same clustering wearing different labels, and choosing between them on the index alone is noise-chasing. The mature use of the measure is to let it veto clearly inferior partitions and shortlist the plausible ones, then let interpretability, stability under resampling and the per-cluster silhouette profiles arbitrate among the finalists. The index ranks; it does not absolve the analyst from judging.
FAQs
What Calinski-Harabasz index does the first example give?
The first example gives a Calinski-Harabasz index of 230.75. Its between dispersion of 1,450 over 3 degrees of freedom (483.33) divided by its within dispersion of 620 over 300 - 4 degrees of freedom (2.0946) produces the highest score of the three examples.
What is the between dispersion per df in the first example?
The between dispersion per degree of freedom in the first example is 483.33: the trace of 1,450 divided by k - 1 = 3. It is the numerator of the index, the separation side of the ratio.
What is the within dispersion per df in the first example?
The within dispersion per degree of freedom in the first example is 2.0946: the trace of 620 divided by n - k = 300 - 4. It is the denominator of the index, the compactness side of the ratio.
What index does the tighter second example give?
The tighter second example gives an index of 185.63. With 3 clusters and 180 points, its between dispersion per degree of freedom is 430.00 against a within value of 2.3164 - solidly separated, but scoring below the first example.
What index does the six-cluster third example give?
The six-cluster third example gives an index of 157.63. Although its between trace of 2,300 is the largest of the three, the degrees-of-freedom charge for 6 clusters and a within trace of 1,500 pull the ratio down to the lowest of the set.
What between dispersion per df does the second example have?
The second example has a between dispersion per degree of freedom of 430.00: its trace of 860 divided by k - 1 = 2. Divided by its within value of 2.3164, that gives the index of 185.63.