Understanding the silhouette score calculator — concept and principle
The silhouette value s(i) measures how well a single data point fits the cluster it was assigned to, compared with the nearest other cluster. Averaged over all points, it becomes the silhouette score that is widely used to compare clusterings and to choose the number of clusters in k-means and similar methods.
How it is calculated
- a(i): the mean distance from point i to all other points in its own cluster (cohesion).
- b(i): for every other cluster, compute the mean distance from i to its points, then take the smallest of these means (separation from the nearest neighbouring cluster).
- s(i) = (b − a) ÷ max(a, b).
The distances can be in any unit (Euclidean, Manhattan, cosine distance) as long as a and b use the same one; s(i) itself is unitless and lies between −1 and 1. By convention, a point that is alone in its cluster gets s(i) = 0.
The principle
A point is well clustered when it is much closer to its own group than to any other group, that is, when a is small compared with b. Dividing the gap b − a by the larger of the two scales it to the range −1 to 1. If a < b, s = 1 − a/b, which approaches 1 as a shrinks. If a = b, s = 0: the point sits on the border between two clusters. If a > b, s = b/a − 1, which is negative: the point is, on average, closer to another cluster than to its own and is probably misassigned.
Worked example
- Inputs: a(i) = 1.2, b(i) = 3.0.
- b − a = 3.0 − 1.2 = 1.8.
- max(a, b) = 3.0.
- s(i) = 1.8 ÷ 3.0 = 0.6.
- Equivalently, s = 1 − 1.2 ÷ 3.0 = 0.6: the point's own cluster is 40% as far away, on average, as the nearest other cluster.
| Mean distance to nearest other cluster b(i) | Silhouette s(i) |
|---|---|
| 0.75 | -0.375 |
| 1.5 | 0.2 |
| 2.25 | 0.4666666667 |
| 3 | 0.6 |
| 3.75 | 0.68 |
| 4.5 | 0.7333333333 |
| 6 | 0.8 |
How to read the result
Values near 1 mean the point is deep inside a compact, well separated cluster; values near 0 mean it lies between clusters; negative values suggest it belongs elsewhere. For the average over a whole dataset, Kaufman and Rousseeuw proposed a rough guide: above 0.70 a strong structure, 0.51–0.70 a reasonable structure, 0.26–0.50 a weak structure that may be artificial, and 0.25 or less no substantial structure. To pick the number of clusters, compute the average for several k and favour the highest, while also looking at per-cluster silhouette plots.
Common mistakes
- Using the distance to the nearest point instead of the mean distance to all points in a cluster.
- Taking b from the farthest other cluster instead of the nearest.
Frequently asked questions
Is a silhouette of 0.6 good?
For one point it means a clear fit. For a dataset average, 0.6 falls in the "reasonable structure" band of the Kaufman and Rousseeuw guide.
Does the silhouette depend on the distance metric?
Yes. Use the same metric that the clustering algorithm optimised, and scale features before computing it.
Sources: P. J. Rousseeuw, "Silhouettes: a graphical aid to the interpretation and validation of cluster analysis", Journal of Computational and Applied Mathematics 20 (1987) 53–65 · L. Kaufman and P. J. Rousseeuw, Finding Groups in Data: An Introduction to Cluster Analysis, Wiley, 1990