Clustering has no labels to score against, so quality must be judged from the data itself: are points close to their own cluster and far from the others? The silhouette score summarises that for each point and averages it.
Implement silhouette_score(X, labels) using Euclidean distance.
X has shape (n_samples, n_features); labels is a length-n_samples integer cluster assignment.a is its mean distance to the other points in its own cluster, and b is the smallest mean distance to the points of any other cluster.0. If max(a, b) == 0, its silhouette is 0.0.0 when there are fewer than two clusters. Return the mean silhouette as a Python float.Open one at a time. Each gives away a little more than the last.
Build the full pairwise distance matrix once with broadcasting.
Then loop over points: mask the same-cluster entries for a, and take a minimum of per-cluster means for b.
No results yet
Run your code to check it against the examples, or submit to run every test.