How good is a clustering when there are no labels? The silhouette compares how close each point is to its own cluster versus the nearest other cluster.
For point i: a = mean distance to the other points in its cluster, b = the smallest mean distance to the points of any other cluster, and . A point alone in its cluster gets .
Implement (with Euclidean distances):
silhouette_samples(X, labels): the array of silhouette_score(X, labels): their meanbest_k(X, label_sets): given a dict {k: labels}, the k with the highest score (ties: smallest k)