How it works...

The sklearn.metrics.silhouette_score function computes the mean silhouette coefficient of all the samples. For each sample, two distances are calculated: the mean intra-cluster distance (x), and the mean nearest-cluster distance (y). The silhouette coefficient for a sample is given by the following equation:

Essentially, y is the distance between a sample and the nearest cluster that does not include the sample.