Silhouette Coefficient Calculator
Inputs
- Inputs: mean distance to points in the same cluster a = 2.40, mean distance to the nearest other cluster b = 5.10.
- The separation gap is b - a = 5.10 - 2.40 = 2.70: positive means the point sits closer to its own cluster than to the neighbour.
- Silhouette = (b - a) / max(a, b) = 2.70 / 5.10 = 0.5294.
- A silhouette of 0.5294 sits between -1 and 1: near 1 the point is well matched to its cluster, near 0 it lies on a boundary, and negative values suggest the wrong cluster.
A clustering can look tidy in a plot and still assign many points to the wrong group. The silhouette coefficient, proposed by Peter Rousseeuw in 1987, grades the assignment point by point: it compares a, the mean distance from a point to the others in its own cluster, with b, the mean distance to the points of the nearest neighbouring cluster. Enter those two distances and the calculator returns the silhouette together with the separation gap and the cohesion ratio behind it.
Because the score is built from just two summary distances, it can be computed for a single point, averaged over a cluster, or averaged over a whole clustering to give the overall silhouette width that analysts quote when comparing algorithms and cluster counts.
Worked examples
Well-assigned point
(2.4 · 5.1)
| Silhouette coefficient | 0.5294 |
| Separation gap (b - a) | 2.70 |
| Cohesion ratio (a / b) | 0.4706 |
Borderline point
(1.8 · 2.1)
| Silhouette coefficient | 0.1429 |
| Separation gap (b - a) | 0.30 |
| Cohesion ratio (a / b) | 0.8571 |
Misassigned point
(4.6 · 4.2)
| Silhouette coefficient | -0.0870 |
| Separation gap (b - a) | -0.40 |
| Cohesion ratio (a / b) | 1.0952 |
What a and b measure
The distance a is a cohesion measure: it says how tightly a point sits inside its own group. A point deep inside a compact cluster has a small a, while a point stranded at the fringe of a sprawling cluster has a large one. The distance b is a separation measure with a twist - it is not the distance to the farthest cluster or the average over all other clusters, but specifically the distance to the nearest rival, the cluster the point would most plausibly defect to.
That choice of the nearest neighbour is what makes the silhouette a diagnostic of assignment rather than of cluster shape. If a point is nearly as close to its nearest rival as to its own cluster, the assignment is a coin flip whatever the global structure looks like, and the silhouette says so.
- a: mean distance to the other points in the same cluster (cohesion).
- b: mean distance to the points of the nearest other cluster (separation).
- Both distances must use the same metric as the clustering itself.
The formula and the role of the maximum
The silhouette is s = (b - a) / max(a, b). Dividing by the larger of the two distances pins the result to the interval from -1 to 1 whatever the scale of the data, which is why silhouettes from different datasets can be compared at all. When b exceeds a, the denominator is b and the score is positive; when a exceeds b, the denominator is a and the score is negative.
The first worked example pairs a = 2.4 with b = 5.1. The separation gap is 2.70 and the score is 2.70 / 5.10 = 0.5294, a comfortably well-assigned point. The cohesion ratio a / b of 0.4706 says the same thing from the other side: the point is, on average, less than half as far from its own cluster-mates as from the nearest rival cluster.
| Example | a | b | Silhouette |
|---|---|---|---|
| First | 2.4 | 5.1 | 0.5294 |
| Second | 1.8 | 2.1 | 0.1429 |
| Third | 4.6 | 4.2 | -0.0870 |
Worked examples
Example 1: a - mean distance within own cluster 2.4; b - mean distance to nearest other cluster 5.1. Silhouette coefficient = 0.5294. Supporting values: Separation gap (b - a) 2.70; Cohesion ratio (a / b) 0.4706. Inputs: mean distance to points in the same cluster a = 2.40, mean distance to the nearest other cluster b = 5.10. The separation gap is b - a = 5.10 - 2.40 = 2.70: positive means the point sits closer to its own cluster than to the neighbour. Silhouette = (b - a) / max(a, b) = 2.70 / 5.10 = 0.5294. A silhouette of 0.5294 sits between -1 and 1: near 1 the point is well matched to its cluster, near 0 it lies on a boundary, and negative values suggest the wrong cluster.
Example 2: a - mean distance within own cluster 1.8; b - mean distance to nearest other cluster 2.1. Silhouette coefficient = 0.1429. Supporting values: Separation gap (b - a) 0.30; Cohesion ratio (a / b) 0.8571. Inputs: mean distance to points in the same cluster a = 1.80, mean distance to the nearest other cluster b = 2.10. The separation gap is b - a = 2.10 - 1.80 = 0.30: positive means the point sits closer to its own cluster than to the neighbour. Silhouette = (b - a) / max(a, b) = 0.30 / 2.10 = 0.1429. A silhouette of 0.1429 sits between -1 and 1: near 1 the point is well matched to its cluster, near 0 it lies on a boundary, and negative values suggest the wrong cluster.
Example 3: a - mean distance within own cluster 4.6; b - mean distance to nearest other cluster 4.2. Silhouette coefficient = -0.0870. Supporting values: Separation gap (b - a) -0.40; Cohesion ratio (a / b) 1.0952. Inputs: mean distance to points in the same cluster a = 4.60, mean distance to the nearest other cluster b = 4.20. The separation gap is b - a = 4.20 - 4.60 = -0.40: positive means the point sits closer to its own cluster than to the neighbour. Silhouette = (b - a) / max(a, b) = -0.40 / 4.60 = -0.0870. A silhouette of -0.0870 sits between -1 and 1: near 1 the point is well matched to its cluster, near 0 it lies on a boundary, and negative values suggest the wrong cluster.
Reading the score: strong, weak and wrong
Practitioners read average silhouettes in rough bands. Values above about 0.5 indicate a clustering with real structure, values between about 0.25 and 0.5 indicate weak structure that may still be worth keeping, and values near 0 or below say the clusters overlap so heavily that the partition is close to arbitrary. These bands are rules of thumb from the original literature, not significance tests.
The second worked example shows the boundary case: a = 1.8 against b = 2.1 gives a gap of only 0.30 and a silhouette of 0.1429. The point is assigned to the nearer cluster, but barely. A clustering full of such points has too many clusters, too few, or a distance metric that does not match the data's geometry.
The misassigned point and what to do about it
The third worked example flips the sign: a = 4.6 against b = 4.2 gives a gap of -0.40, a cohesion ratio of 1.0952 and a silhouette of -0.0870. The point sits closer to the neighbouring cluster than to the one it was assigned to. In a silhouette plot - the bar chart of per-point scores that gives the method its name - such points show up as bars poking through the axis into negative territory.
A handful of negative points usually marks outliers or bridge points between genuine groups, and reassigning them rarely changes the analysis. A whole cluster with a negative average, by contrast, usually means the algorithm was forced to invent a group the data does not contain, and the honest response is to reduce the cluster count or change the metric.
Averaging silhouettes and choosing k
The overall silhouette width of a clustering is the mean of the per-point scores, and it is the standard single number for choosing the number of clusters k: run the algorithm for several values of k and keep the one with the highest average. The per-cluster averages are just as informative, because a clustering can score well overall while one bloated cluster drags a low average of its own.
Two cautions complete the picture. The silhouette favours compact, round, evenly sized clusters, so it can unfairly penalise elongated or density-based groupings that are genuinely correct. And it inherits every weakness of the distance metric fed into it: with a meaningless metric, a and b are meaningless, and no ratio of the two can rescue the analysis.
In practice the per-point scores are usually read as a plot before they are read as a number: each cluster becomes a horizontal blade of sorted silhouettes, and the shape of the blades - their width, their average, how many points dip below zero - shows at a glance which clusters are compact and which are stragglers wearing a cluster's name. A clustering whose overall average is carried by one wide blade while another blade sits mostly negative is not a good clustering with a blemish; it is two findings, and the average alone conceals the second one.
FAQs
What silhouette does the first example give?
The first example gives a silhouette of 0.5294. With a = 2.4 and b = 5.1, the gap of 2.70 divided by the maximum distance of 5.10 lands well into positive territory - a point clearly matched to its own cluster.
What separation gap does the first example have?
The first example has a separation gap of 2.70, the difference b - a = 5.10 - 2.40. A positive gap means the point sits closer to its own cluster than to the nearest neighbouring cluster.
What cohesion ratio does the first example have?
The first example has a cohesion ratio of 0.4706, which is a / b = 2.40 / 5.10. The point is on average less than half as far from its cluster-mates as from the nearest rival cluster.
What silhouette does the borderline second example give?
The borderline second example gives a silhouette of 0.1429. Its gap is only 0.30 on distances of 1.8 and 2.1, so the point is assigned to the nearer cluster but sits close to the boundary between the two.
What silhouette does the misassigned third example give?
The misassigned third example gives a silhouette of -0.0870. Its own-cluster distance of 4.6 exceeds its nearest-neighbour distance of 4.2, so on average the point belongs with the neighbouring cluster instead.
What separation gap does the third example have?
The third example has a separation gap of -0.40, from b - a = 4.20 - 4.60. The negative sign is the tell: the separation the formula looks for has inverted, and the assignment is wrong for that point.