Tutorials › Exam PA - Predictive Analytics › Comparing Cluster Counts With Internal Indices

Exam PA · Clustering and Similarity Structure · Tutorial 604 of 966

Comparing Cluster Counts With Internal Indices

Calculate and compare two internal clustering indices while keeping their assumptions and limitations in view.

Intermediate 12 min read

What You'll Learn

  • Define the cluster-centroid scatter and separation used by the Davies–Bouldin index
  • Calculate and interpret the Davies–Bouldin index for candidate partitions
  • Calculate within-cluster and between-cluster sums of squares for the Calinski–Harabasz index
  • Compare candidate cluster counts using each index’s preferred direction
  • Explain the Euclidean-centroid assumptions behind these indices
  • Recognize why an internal index cannot establish the true grouping

Why Compare Internal Indices?

A clustering algorithm can produce a partition for many different choices of cluster count. Internal indices summarize aspects of that partition using the observed data: they assess how compact clusters are and, in different ways, how separated they are. They can help compare candidate partitions, but they do not supply labels or prove that the groups correspond to meaningful populations.

This tutorial defines two commonly used indices. The Davies–Bouldin index compares each cluster’s scatter with its separation from other cluster centers; smaller values are preferred. The Calinski–Harabasz index compares between-cluster variation with within-cluster variation while accounting for degrees of freedom; larger values are preferred. Their different constructions mean they need not select the same cluster count.

Definition: Let \(n\) observations be partitioned into \(k\) nonempty clusters \(C_1,\ldots,C_k\). For the formulas below, use Euclidean distance and define the centroid of cluster \(i\) as \(c_i\). The overall centroid is \(c\). The Davies–Bouldin index uses the average distance of cluster members from their centroid as a scatter measure. The Calinski–Harabasz index uses sums of squared Euclidean distances from members to their cluster centroid and from cluster centroids to the overall centroid.

These definitions matter because software and references can use different distance choices or scatter conventions. When comparing computed values, use the same definition, variables, distance scale, and observations for every candidate partition. A value calculated under one convention should not be compared uncritically with a value calculated under another.

The Davies–Bouldin Index

For cluster \(i\), let \(n_i\) be its number of observations and define its average within-cluster scatter by

$$ S_i=\frac{1}{n_i}\sum_{x\in C_i}\lVert x-c_i\rVert. $$

Let \(M_{ij}=\lVert c_i-c_j\rVert\) be the Euclidean distance between the centroids of clusters \(i\) and \(j\). For each pair of clusters, form the ratio of their combined scatter to their separation:

$$ R_{ij}=\frac{S_i+S_j}{M_{ij}}, \qquad i\ne j. $$

For each cluster, retain its largest such ratio, and average those worst-case values:

$$ D_i=\max_{j\ne i}R_{ij}, \qquad \operatorname{DB}=\frac{1}{k}\sum_{i=1}^{k}D_i. $$

A small Davies–Bouldin value indicates that, for each cluster, even its most problematic comparison has relatively little scatter compared with the distance between centers. It is not a probability, and there is no universal threshold at which a clustering becomes “good.” The index is undefined if two distinct cluster centroids coincide, because then \(M_{ij}=0\).

Worked Example: Comparing Two and Three Clusters With Davies–Bouldin

Six hypothetical service locations have values \(0,2,4,6,8,10\) on a single measured feature. Compare the Davies–Bouldin index for a two-cluster partition, \(C_1=\{0,2,4\}\) and \(C_2=\{6,8,10\}\), with a three-cluster partition, \(C_1=\{0,2\}\), \(C_2=\{4,6\}\), and \(C_3=\{8,10\}\). Use the stated average-distance scatter and Euclidean distance. The method is to calculate each centroid and scatter, then find each cluster’s largest pairwise ratio.

Two clusters. The centroids are \(c_1=(0+2+4)/3=2\) and \(c_2=(6+8+10)/3=8\). The first cluster’s distances to its centroid are \(2,0,2\), so \(S_1=(2+0+2)/3=4/3\). By the same calculation, \(S_2=4/3\). Their centroid distance is \(M_{12}=|8-2|=6\). Thus \(R_{12}=(4/3+4/3)/6=(8/3)/6=4/9\). Each cluster has only one other cluster, so \(D_1=D_2=4/9\), and \(\operatorname{DB}=(4/9+4/9)/2=4/9\), or \(0.4444\) to four decimal places.

Three clusters. The centroids are \(1,5,9\), and each cluster has distances \(1,1\) from its centroid. Thus \(S_1=S_2=S_3=1\). The centroid distances are \(M_{12}=4\), \(M_{23}=4\), and \(M_{13}=8\). Therefore \(R_{12}=2/4=0.5\), \(R_{23}=2/4=0.5\), and \(R_{13}=2/8=0.25\). The largest ratios are \(D_1=0.5\), \(D_2=0.5\), and \(D_3=0.5\), giving \(\operatorname{DB}=(0.5+0.5+0.5)/3=0.5000\) to four decimal places.

Interpretation and check. The two-cluster partition has the lower index, \(0.4444<0.5000\), so it is preferred by this index for these data and this definition. The calculation avoids a common mistake: using only the distance between centroids and forgetting that the numerator must include both clusters’ scatters.

The Calinski–Harabasz Index

For a partition into \(k\) nonempty clusters, define the within-cluster sum of squares \(W\), the between-cluster sum of squares \(B\), and the Calinski–Harabasz index as follows:

$$ W=\sum_{i=1}^{k}\sum_{x\in C_i}\lVert x-c_i\rVert^2, \qquad B=\sum_{i=1}^{k}n_i\lVert c_i-c\rVert^2, $$
$$ \operatorname{CH} = \frac{B/(k-1)}{W/(n-k)} = \frac{B}{W}\frac{n-k}{k-1}. $$

The numerator \(B/(k-1)\) is the between-cluster sum of squares per between-cluster degree of freedom; the denominator \(W/(n-k)\) is the within-cluster sum of squares per within-cluster degree of freedom. A larger ratio is preferred: it indicates more between-cluster variation relative to within-cluster variation, after these degrees-of-freedom adjustments.

The index requires \(k\ge 2\), \(n>k\), and \(W>0\) for the displayed ratio to be finite. It is based on squared Euclidean distances to centroids. It is not a significance test, and its value does not show that the clusters are genuine groups in the population.

Why the sums decompose: With Euclidean centroids, total squared variation about the overall centroid equals within-cluster variation plus between-cluster variation. For any observation \(x\in C_i\), write \(x-c=(x-c_i)+(c_i-c)\). On squaring and summing, the cross-product terms vanish because \(\sum_{x\in C_i}(x-c_i)=0\) for every cluster. Therefore
$$ \sum_{i=1}^{k}\sum_{x\in C_i}\lVert x-c\rVert^2=W+B. $$

This decomposition explains the contrast in the index: the Calinski–Harabasz numerator measures the part of total squared variation associated with differences between cluster centroids, while the denominator measures variation remaining within clusters. The degrees-of-freedom factors adjust the ratio for the number of clusters and observations; they do not remove the need to interpret the result in context.

Worked Example: Calculating Calinski–Harabasz for the Same Candidate Counts

Use the six values \(0,2,4,6,8,10\), whose overall centroid is \(c=(0+2+4+6+8+10)/6=5\). Compare the two partitions from the preceding calculation. The method is to calculate \(W\) and \(B\) separately for each partition, then apply the degrees-of-freedom factors. A common error is to omit those factors and compare \(B/W\) alone.

Two clusters. The cluster centroids are \(2\) and \(8\). In the first cluster, the squared deviations from \(2\) are \(4,0,4\), which sum to \(8\); the second cluster also contributes \(8\). Thus \(W=8+8=16\). For \(B\), each cluster has size \(3\), and each centroid is \(3\) units from the overall centroid \(5\). Therefore \(B=3(2-5)^2+3(8-5)^2=27+27=54\). With \(n=6\) and \(k=2\), \(\operatorname{CH}=(54/1)/(16/4)=54/4=13.5\).

Three clusters. The centroids are \(1,5,9\). Each pair of observations is one unit from its cluster centroid, so each cluster contributes \(1^2+1^2=2\) to \(W\), giving \(W=6\). The centroid \(1\) contributes \(2(1-5)^2=32\) to \(B\), the centroid \(5\) contributes \(2(5-5)^2=0\), and the centroid \(9\) contributes \(2(9-5)^2=32\). Thus \(B=64\). With \(k=3\), \(\operatorname{CH}=(64/2)/(6/3)=32/2=16\).

Interpretation and check. The three-cluster partition has the larger Calinski–Harabasz index, \(16>13.5\), even though the two-cluster partition had the lower Davies–Bouldin index. The calculations check against the decomposition: the total squared variation is \(70\); for two clusters, \(W+B=16+54=70\), and for three clusters, \(W+B=6+64=70\). The disagreement is a reminder that an index is a particular summary, not a definitive answer.

What Each Index Emphasizes

IndexConstructionPreferred directionImportant limitation
Davies–BouldinAverages each cluster’s largest ratio of combined scatter to centroid separationLowerUses centroid distances and a selected scatter definition
Calinski–HarabaszCompares between-cluster and within-cluster squared variation, with degrees-of-freedom adjustmentsHigherUses Euclidean centroids and squared distances

The Davies–Bouldin index gives each cluster one contribution after comparing it with its most similar competitor. It can therefore be driven by a particularly close or diffuse pair. The Calinski–Harabasz index aggregates squared deviations over all observations and incorporates \(n\) and \(k\) through its degrees of freedom. Neither construction is neutral: changing the number of clusters can change both the underlying variation and the adjustment.

Worked Example: Identifying the Limiting Comparison

A hypothetical three-cluster partition has centers \(c_1=(1,0)\), \(c_2=(7,0)\), and \(c_3=(1,8)\). In every cluster, the two observations are one unit from the centroid, so \(S_1=S_2=S_3=1\). Calculate and interpret the Davies–Bouldin index. This example tests whether the maximum pairwise ratio is selected separately for each cluster.

The centroid distances are \(M_{12}=6\), \(M_{13}=8\), and \(M_{23}=\sqrt{(7-1)^2+(0-8)^2}=\sqrt{36+64}=10\). The pairwise ratios are \(R_{12}=(1+1)/6=1/3\), \(R_{13}=2/8=1/4\), and \(R_{23}=2/10=1/5\).

For cluster 1, the larger ratio is \(D_1=\max(1/3,1/4)=1/3\). For cluster 2, it is \(D_2=\max(1/3,1/5)=1/3\). For cluster 3, it is \(D_3=\max(1/4,1/5)=1/4\). Hence \(\operatorname{DB}=(1/3+1/3+1/4)/3=(11/12)/3=11/36=0.3056\) to four decimal places.

The two clusters with centers 1 and 7 are the limiting comparison for clusters 1 and 2; their ratio is larger than either cluster’s other ratio. Taking the average of all three pairwise ratios instead would give \((1/3+1/4+1/5)/3\), which is not the defined index. The required operation is first to take each cluster’s maximum, then average those maxima.

Assumptions, Comparability, and Interpretation

Both indices are most straightforward to interpret when features are quantitative and Euclidean distances are appropriate for the question. Centroid-based summaries can be misleading when a centroid is not representative of its cluster, and a numerical index cannot repair a poor choice of variables or scale. Earlier material on distance matrices and redundant predictors is relevant here: the chosen representation determines what “near” and “far” mean.

For a fair comparison, keep the observations and feature representation fixed while varying the candidate partition. Check that clusters are nonempty, that the number of clusters meets the index’s requirements, and that calculations use the same distance and scatter conventions. Do not compare raw index values across different data sets as if they had a universal scale.

A disciplined interpretation is to report the index, its preferred direction, the candidate partitions compared, and the important limitation. If the two indices disagree, report that disagreement rather than choosing whichever number supports a preferred conclusion. The result is evidence about compactness and separation under specific definitions; it is not proof of a single true grouping.

Key takeaway: The Davies–Bouldin index is minimized and summarizes each cluster’s worst scatter-to-separation comparison. The Calinski–Harabasz index is maximized and compares between-cluster with within-cluster squared variation, adjusted for degrees of freedom. Neither index alone establishes the correct number or meaning of clusters.

Check Your Understanding

For each question, apply the stated definitions and keep the preferred direction of the index in mind.

  1. A two-cluster partition has average scatters \(S_1=0.6\) and \(S_2=1.0\), and the centroids are 8 units apart. What is its Davies–Bouldin index? (Answer: \(0.2000\))
  2. A partition has \(n=8\), \(k=2\), \(B=72\), and \(W=24\). Calculate its Calinski–Harabasz index. (Answer: \(18\))
  3. Three clusters each have scatter \(1\). Their centroids lie on a line at positions \(0,5,10\). Calculate the Davies–Bouldin index. (Answer: \(0.4000\))
  4. Candidate A has \(n=12\), \(k=3\), \(B=90\), and \(W=30\). Candidate B has \(n=12\), \(k=2\), \(B=80\), and \(W=40\). Calculate both Calinski–Harabasz indices and identify which has the larger value. (Answer: A is \(13.5\), B is \(20\); B has the larger index.)
  5. The Davies–Bouldin index prefers one candidate partition, while the Calinski–Harabasz index prefers another. What conclusion is justified from these results alone? (Answer: The indices rank the candidates differently under their respective definitions; neither result alone establishes the true grouping.)
Clinical Biostats