Tabellab
Data, tech, science & health

Silhouette score explained: the formula and a worked example

The silhouette score measures how well each point fits its cluster: s = (b − a) ÷ max(a, b), where a is the mean distance to the other members of its own cluster and b the mean distance to the members of the nearest other cluster. Scores run from −1 to +1, and the average over all points rates the whole clustering. In the example, eight stores in two clusters reach an average silhouette of 0.664, a reasonable structure, while store S5 fits worst with 0.234 because it sits close to the other cluster.

Updated 21 Oct 2026 5 min read By Tabellab team

What the silhouette score measures

A good clustering has two properties: points are close to their own cluster (cohesion) and far from the next one (separation). The silhouette, introduced by Peter Rousseeuw in 1987, puts both into one number per point. It needs only the cluster labels and the distances between points, so it works for k-means, k-medoids or hierarchical clustering alike.

The example uses a single feature, the average basket per store, so every distance is a simple difference and the arithmetic stays visible. With several features only the distance changes: use the Euclidean distance on scaled features.

Worked example: silhouette of eight stores in two clusters

Average basket and cluster label per store are inputs (yellow). Column D calculates a, column E calculates b and column F the silhouette s. Rows 11 to 16 summarise the clustering: the overall and per-cluster averages, the lowest value, the store that fits worst and the number of weak fits.

Worked example: silhouette of eight stores in two clusters
ABCDEF
1StoreAvg basket (USD)Clustera: own clusterb: nearest otherSilhouette s
2S12215.66722.7500.751
3S22513.66719.7500.814
4S32713.66717.7500.793
5S43116.33313.7500.539
6S53829.00011.7500.234
7S64425.00017.7500.718
8S74725.00020.7500.759
9S85027.00023.7500.705
10
11Average silhouette, all stores0.664
12Average silhouette, cluster 10.725
13Average silhouette, cluster 20.604
14Lowest silhouette0.234
15Store that fits worstS5
16Stores with s below 0.25 (weak fit)1
Key formulas
  • D2=SUMPRODUCT((C$2:C$9=C2)*ABS(B$2:B$9-B2))/(COUNTIF(C$2:C$9,C2)-1)a: mean distance to the other members of the own cluster
  • E2=SUMPRODUCT((C$2:C$9<>C2)*ABS(B$2:B$9-B2))/COUNTIF(C$2:C$9,"<>"&C2)b: mean distance to the other cluster
  • F2=(E2-D2)/MAX(D2,E2)Silhouette of S1
  • F11=AVERAGE(F2:F9)Average silhouette

Fictional stores with one feature so the distances are easy to follow. With two clusters, b is the mean distance to the other cluster. With more clusters, take the smallest mean distance to any other cluster.

Step 1: a, the mean distance inside the own cluster

For store S1 (22 USD) the other members of cluster 1 are S2, S3 and S4 at 25, 27 and 31 USD. The distances are 3, 5 and 9, so a = (3 + 5 + 9) ÷ 3 = 5.667. The point's distance to itself (0) must not count, so divide by the number of members minus one. In Excel: =SUMPRODUCT((C$2:C$9=C2)*ABS(B$2:B$9-B2))/(COUNTIF(C$2:C$9,C2)-1).

Step 2: b, the mean distance to the nearest other cluster

S1's distances to the four stores of cluster 2 (38, 44, 47 and 50 USD) are 16, 22, 25 and 28, so b = 91 ÷ 4 = 22.750. With two clusters there is only one other cluster. With more, calculate the mean distance to every other cluster and take the smallest: b always refers to the nearest neighbour cluster, the one the point would most plausibly belong to instead.

Step 3: the silhouette s and the average

s = (b − a) ÷ max(a, b) = (22.750 − 5.667) ÷ 22.750 = 0.751 for S1. Dividing by the larger of the two keeps s between −1 and +1. In Excel: =(E2-D2)/MAX(D2,E2). A point that is alone in its cluster gets s = 0 by convention.

The average silhouette over all points summarises the clustering: 0.664 here. The averages per cluster show where the weakness is: 0.725 for cluster 1 but only 0.604 for cluster 2, pulled down by S5. In Python, silhouette_samples() and silhouette_score() in scikit-learn return the same per-point values and average.

How to read silhouette values

  • Close to +1: the point sits deep inside its cluster, far from the others.
  • Around 0: the point lies on the border between two clusters.
  • Negative: the point is, on average, closer to another cluster and is probably in the wrong one.

Common rules of thumb for the average, going back to Kaufman and Rousseeuw: above 0.70 strong structure, 0.50 to 0.70 reasonable, 0.25 to 0.50 weak, below 0.25 no substantial structure. S5 at 0.234 is a border case: its own cluster is on average 9 USD away, the other one only 11.75 USD. Move S5 into cluster 1 and its silhouette turns negative, about −0.23, a clear sign that the original assignment was the better one.

Using the silhouette to choose k

Run the clustering for k = 2, 3, 4 … and compute the average silhouette for each. The k with the highest average is the silhouette's choice. It often differs from the elbow in the within-cluster sum of squares, because the silhouette rewards clean separation and the elbow rewards compactness, so report both. Two cautions: the score depends on the distance measure (Euclidean, Manhattan or cosine), and it favours round, convex clusters, so it can undervalue long or irregular clusters that density-based methods such as DBSCAN find.

Common mistakes

  • Counting the point itself in a. Dividing by the cluster size instead of size − 1 includes the zero self-distance and makes every cluster look tighter.
  • Using all other points for b. b is the mean distance to the nearest other cluster, not to every point outside the own cluster.
  • Unscaled features. With revenue in dollars and size in square metres, the larger scale decides every distance. Scale the features before clustering and before computing the silhouette.
  • Comparing scores across distance measures. A silhouette with Manhattan distance is not comparable with one computed with Euclidean distance.
  • Looking only at the average. A good average can hide one poor cluster or a few misassigned points. Check per-cluster averages and the lowest values.
  • Scoring density-based clusters. DBSCAN noise points and irregular clusters are judged unfairly by a measure built for compact, convex clusters.

Frequently asked questions

What is a good silhouette score?

As a rule of thumb, an average above 0.70 indicates strong structure, 0.50 to 0.70 reasonable structure, 0.25 to 0.50 weak structure and below 0.25 no substantial structure. Compare scores on the same data rather than across datasets.

What does a negative silhouette score mean?

The point is on average closer to the members of another cluster than to its own, so it is probably assigned to the wrong cluster. A negative average means the clustering as a whole is poor.

How is the silhouette score calculated?

For each point, a is the mean distance to the other points in its cluster and b the mean distance to the points of the nearest other cluster. The point's silhouette is (b − a) ÷ max(a, b), and the score is the average over all points.

Is the silhouette method better than the elbow method?

Neither is always better. The elbow looks for diminishing returns in within-cluster variance, the silhouette for the best separation. They often disagree, so report both and decide with the business question.

Practise it in a lab

Related guides

Reading is step one. Doing is step two.

Every guide links to a lab where you build the same calculation in an online spreadsheet and get instant feedback.

Open the lab