snf.metrics.silhouette_score

snf.metrics.silhouette_score(arr, labels)[source]

Calculates modified silhouette score from affinity matrix

The Silhouette Coefficient is calculated using the mean intra-cluster affinity (a) and the mean nearest-cluster affinity (b) for each sample. The Silhouette Coefficient for a sample is (b - a) / max(a,b). To clarify, b is the distance between a sample and the nearest cluster that the sample is not a part of. This corresponds to the cluster with the next highest affinity (opposite how this metric would be computed for a distance matrix).

Parameters:
  • arr ((N, N) array_like) – Array of pairwise affinities between samples
  • labels ((N,) array_like) – Predicted labels for each sample
Returns:

silhouette_score – Modified (affinity) silhouette score

Return type:

float

Notes

Code is lightly modified from the sklearn implementation. See: sklearn.metrics.silhouette_score