Why Use Silhouette Widths?
A k-means solution assigns each observation to a cluster, but the assignment alone does not say how well that observation fits. An observation may be close to other members of its assigned cluster and far from every alternative, or it may be almost as close to another cluster as to its assigned one. A silhouette width summarizes that comparison for one observation. Averaging the widths gives a summary for a whole clustering solution.
Silhouettes are based on distances between observations, not on distances to cluster centers. The distance measure should be specified and used consistently. For numeric features, Euclidean distance is common; the calculation below works with any selected dissimilarity for which pairwise distances are defined. As with other distance-based methods, feature scaling affects the distances and therefore can affect silhouettes.
Computing the Two Distances
The calculation has two distinct parts. First, \(a(i)\) measures the average distance from \(i\) to the other observations in its assigned cluster. The observation itself is excluded; including its distance of zero would artificially reduce the average. Second, calculate an average distance from \(i\) to each alternative cluster separately. The smallest of those averages is \(b(i)\), the distance to the nearest alternative cluster in this average-distance sense.
The nearest alternative cluster is not necessarily the cluster containing the single closest observation. A cluster with one nearby point and many distant points can have a larger average distance than another cluster whose observations are all moderately close. The definition compares cluster averages, not individual nearest neighbors.
Worked Example: Calculating Silhouettes for Two Clusters
A hypothetical portfolio segmentation has two clusters on a one-dimensional risk score scale. Their scores are \(C_1=\{0,2\}\) and \(C_2=\{5,7\}\), and distance is absolute difference. Calculate every observation’s silhouette and the overall average.
Method. For each observation, average its distances to the other member of its own cluster, calculate the average distance to the other cluster, and substitute into the silhouette formula.
For score \(0\), the within-cluster average is \(a(0)=|0-2|=2\). The average distance to \(C_2\) is \((|0-5|+|0-7|)/2=(5+7)/2=6\), so \(b(0)=6\). Thus \(s(0)=(6-2)/6=4/6=2/3\).
For score \(2\), \(a(2)=|2-0|=2\). The average distance to \(C_2\) is \((|2-5|+|2-7|)/2=(3+5)/2=4\). Therefore \(b(2)=4\), and \(s(2)=(4-2)/4=1/2\).
For score \(5\), \(a(5)=|5-7|=2\). The average distance to \(C_1\) is \((|5-0|+|5-2|)/2=(5+3)/2=4\). Hence \(b(5)=4\), and \(s(5)=(4-2)/4=1/2\).
For score \(7\), \(a(7)=|7-5|=2\). The average distance to \(C_1\) is \((|7-0|+|7-2|)/2=(7+5)/2=6\). Thus \(b(7)=6\), and \(s(7)=(6-2)/6=2/3\).
The overall average is \(\{2/3+1/2+1/2+2/3\}/4=(7/3)/4=7/12\), or \(0.5833\) to four decimal places. The positive widths indicate that each observation’s average distance to its own cluster is smaller than its average distance to the nearest alternative cluster. The common mistake avoided here is using the distance to a cluster center instead of the required average of pairwise distances.
Interpreting the Formula
The numerator compares the two averages: \(b(i)-a(i)\) measures the assigned cluster’s advantage over the nearest alternative. It is positive when the observation is, on average, closer to its assigned cluster. The denominator puts the difference on a scale determined by the larger of the two distances.
The usual range is from \(-1\) to \(1\), provided the denominator is positive. To see why, consider the two possible orderings. If \(b(i)\geq a(i)\), then \(s(i)=1-a(i)/b(i)\), which lies between \(0\) and \(1\). If \(a(i)>b(i)\), then \(s(i)=b(i)/a(i)-1\), which lies between \(-1\) and \(0\). If both averages are zero, the displayed ratio is undefined; implementations typically set the width to zero by convention. This degenerate case represents no distance-based separation.
A singleton cluster has no other member from which to calculate \(a(i)\), so its silhouette is conventionally set to zero. This convention prevents an undefined within-cluster average from being treated as strong evidence of a good fit. It also means that a solution with many singleton clusters can have an average silhouette affected by those zero values.
Worked Example: Finding the Nearest Alternative and Handling a Singleton
A hypothetical group of service locations is partitioned on a one-dimensional scale into \(C_1=\{0,1\}\), \(C_2=\{3,4\}\), and \(C_3=\{10\}\). Use absolute distance to calculate the silhouettes for observations \(0\), \(1\), and \(10\). In particular, identify the nearest alternative by comparing cluster averages.
For observation \(0\): \(a(0)=|0-1|=1\). The average distance to \(C_2\) is \((|0-3|+|0-4|)/2=(3+4)/2=3.5\). The average distance to \(C_3\) is \(|0-10|=10\). The smaller average is \(3.5\), so \(b(0)=3.5\) and \(s(0)=(3.5-1)/3.5=2.5/3.5=5/7\), or \(0.7143\) to four decimal places.
For observation \(1\): \(a(1)=|1-0|=1\). The average distance to \(C_2\) is \((|1-3|+|1-4|)/2=(2+3)/2=2.5\). The distance to \(C_3\) is \(|1-10|=9\). Therefore \(b(1)=2.5\), and \(s(1)=(2.5-1)/2.5=1.5/2.5=0.6000\).
For observation \(10\): its assigned cluster \(C_3\) is a singleton. There is no other member in that cluster, so the conventional silhouette is \(s(10)=0\). Do not calculate a within-cluster average using the observation’s self-distance as if it were another member.
The nearest alternative for \(0\) and \(1\) is \(C_2\), not \(C_3\), because the comparison uses the average distance to each alternative cluster. The key trap is to select the closest alternative based on one pair of observations rather than on the cluster-level averages required by the definition.
Comparing Candidate Values of K
For a clustering of \(n\) observations, the average silhouette is the arithmetic mean of the \(n\) individual widths:
To compare candidate values of \(K\), calculate each solution’s average silhouette using the same observations, distance definition, and feature preparation. A larger average indicates that, on balance, observations have a more favorable distance to their assigned clusters relative to their nearest alternatives. It is a useful comparison criterion, not a proof that one partition is the uniquely correct description of the data.
The comparison should be read alongside the individual widths and cluster assignments. A reasonable average can conceal a small group of observations with negative widths, while singleton clusters contribute zero under the usual convention. Also, \(K=1\) has no alternative cluster, so silhouettes are not defined for that solution. At \(K=n\), every cluster is a singleton and the conventional average is zero; that extreme does not provide a meaningful assessment of separation.
Worked Example: Comparing Two Candidate Clusterings
Six hypothetical claim profiles have one-dimensional scores \(0,1,2,8,9,10\), with absolute distance. For \(K=2\), the assigned clusters are \(\{0,1,2\}\) and \(\{8,9,10\}\). For \(K=3\), they are \(\{0,1\}\), \(\{2\}\), and \(\{8,9,10\}\). Calculate both average silhouettes and state which candidate has the larger value.
For \(K=2\): For score \(0\), \(a=(1+2)/2=1.5\), and the other-cluster average is \((8+9+10)/3=9\). Thus \(s(0)=(9-1.5)/9=5/6\). For score \(1\), \(a=(1+1)/2=1\), and the other-cluster average is \((7+8+9)/3=8\), giving \(s(1)=7/8\). For score \(2\), \(a=(2+1)/2=1.5\), and the other-cluster average is \((6+7+8)/3=7\), giving \(s(2)=(7-1.5)/7=11/14\).
The data and partition are symmetric around \(5\), so scores \(10,9,8\) have the same respective widths as \(0,1,2\). Therefore \(\bar{s}_{K=2}=\{2(5/6+7/8+11/14)\}/6\). Using denominator \(168\), the sum in parentheses is \((140+147+132)/168=419/168\). Hence \(\bar{s}_{K=2}=419/504=0.8313\) to four decimal places.
For \(K=3\): Score \(0\) has \(a=1\). Its average distance to the singleton \(\{2\}\) is \(2\), while its average to \(\{8,9,10\}\) is \(9\). Thus \(b=2\) and \(s(0)=1/2\). Score \(1\) also has \(a=1\); its distance to \(\{2\}\) is \(1\), while its average to \(\{8,9,10\}\) is \((7+8+9)/3=8\). Thus \(b=1\) and \(s(1)=0\). Score \(2\) is a singleton, so \(s(2)=0\).
For score \(8\), \(a=(1+2)/2=1.5\). The average distance to \(\{2\}\) is \(6\), and the average to \(\{0,1\}\) is \((8+7)/2=7.5\). Therefore \(b=6\) and \(s(8)=(6-1.5)/6=3/4\). By symmetry, \(s(10)=13/16\), since its within-cluster average is \(1.5\) and its nearest alternative average is \(8\). For score \(9\), \(a=(1+1)/2=1\) and \(b=7\), so \(s(9)=6/7\).
The \(K=3\) average is \((1/2+0+0+3/4+6/7+13/16)/6\). The sum is \((56+84+96+91)/112=327/112\), so \(\bar{s}_{K=3}=327/672=0.4866\) to four decimal places. In this comparison, \(K=2\) has the larger average silhouette. The singleton’s zero and the zero width at score \(1\) both matter; omitting either would produce the wrong comparison.
Common Mistakes and Practical Use
Silhouette widths are informative because they put within-cluster cohesion and nearest-alternative separation into one interpretable quantity. They help identify observations that fit poorly and provide a consistent summary for comparing candidate cluster counts. They do not replace examination of the data, the distance choice, or the substantive meaning of a proposed segmentation.
- Reversing the sign interpretation. If \(b(i)-a(i)>0\), the assigned cluster is closer on average than the nearest alternative; a positive width is not evidence that the alternative is closer.
- Using a single nearest point. Calculate the average distance to every alternative cluster, then take the smallest cluster average to obtain \(b(i)\).
- Including self-distance in \(a(i)\). Average over the other members only. A singleton has no such average and receives the conventional width zero.
- Comparing incompatible calculations. Candidate solutions should use the same observations and distance setup. Changing feature scaling changes the distance inputs and can change the silhouettes.
- Treating the largest average as an automatic answer. The average is a summary. Inspect individual widths and cluster sizes before deciding whether the partition is useful for the application.
Check Your Understanding
Work through each distance comparison before using the silhouette formula. Answers are given at the end of each question for checking.
- On a one-dimensional scale, an observation with score \(4\) belongs to cluster \(\{1,4\}\); the only other cluster is \(\{7,9\}\). Using absolute distance, calculate \(a(4)\), \(b(4)\), and \(s(4)\). (Answer: \(a=3\), \(b=4\), \(s=0.2500\).)
- Score \(2\) belongs to \(\{1,2,4\}\), and the alternative cluster is \(\{8,10\}\). Use absolute distance to calculate the silhouette for score \(2\). (Answer: \(a=1.5\), \(b=7\), \(s=0.7857\) to four decimal places.)
- Score \(0\) belongs to \(\{0,2\}\). The two alternative clusters are \(\{4,6\}\) and \(\{9\}\). Find the nearer alternative cluster using average distances, then calculate the silhouette for score \(0\). (Answer: the nearer alternative is \(\{4,6\}\), \(a=2\), \(b=5\), and \(s=0.6000\).)
- A clustering has five observations with silhouettes \(-0.2, 0.4, 0.6, 0,\) and \(0.7\). Calculate the average and explain what the negative value flags. (Answer: average \(=1.5/5=0.3000\); the observation with width \(-0.2\) is closer on average to an alternative cluster than to its assigned cluster.)
- Two candidate solutions use the same observations and distance measure. Their average silhouettes are \(0.48\) for \(K=2\) and \(0.61\) for \(K=3\). The \(K=3\) solution also has one singleton cluster. Which solution has the larger reported average, and what additional check is appropriate before choosing it? (Answer: \(K=3\) has the larger reported average, \(0.61\); inspect individual widths and the cluster assignments, including the singleton, rather than selecting \(K\) from the average alone.)