Clustering has no labels to check against, so how do you know whether the clusters are any good? The silhouette score asks, for each point: is it closer to its own cluster than to the nearest other one?
For point i:
i to the other points in its own clusteri to the points of the nearest other cluster, taking the minimum over all other clustersTask: write silhouette_score(points, labels) returning the mean of s over all points, rounded to 4 decimal places. Use Euclidean distance.
0.0 by convention — a is undefined there.b averages over all points of the other cluster, then takes the minimum across clusters. Don't take the single nearest point.The score runs from -1 to 1. Near 1 means tight, well-separated clusters; near 0 means points sitting on a boundary; negative means points would be better off in the neighbouring cluster — which usually means you picked the wrong
k.