Search code examples
pythonscikit-learncluster-analysissklearn-pandas

How to calculate Silhouette coefficient for k-mediod clustering using pyclustering lib?


I like try the k-mediod clustering method (PAM) over the dataset https://archive.ics.uci.edu/ml/datasets/seeds

I don't know whether there exists other libraries other than pyclustering for this purpose. Anyway, how can I compute Silhouette coefficient for the clustering using this library? It don't provide such a method as an k-means with sklearn.


Solution

  • From the documentation, you can use sklearn.metrics.silhouette_score(X, labels, metric=’euclidean’, sample_size=None, random_state=None, **kwds). This function returns the mean Silhouette Coefficient over all samples. To obtain the values for each sample, use silhouette_samples. I also recommend to see this vignette. There is a nice example in there for you to test too.