Skip to content

Instantly share code, notes, and snippets.

@khyatimahendru
Created June 17, 2019 06:41
Show Gist options
  • Select an option

  • Save khyatimahendru/2f7ff7c17ea13a28d5023f3aefa047e2 to your computer and use it in GitHub Desktop.

Select an option

Save khyatimahendru/2f7ff7c17ea13a28d5023f3aefa047e2 to your computer and use it in GitHub Desktop.
from sklearn.metrics import silhouette_score
sil = []
kmax = 10
# dissimilarity would not be defined for a single cluster, thus, minimum number of clusters should be 2
for k in range(2, kmax+1):
kmeans = KMeans(n_clusters = k).fit(x)
labels = kmeans.labels_
sil.append(silhouette_score(x, labels, metric = 'euclidean'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment