Created
November 20, 2020 03:43
-
-
Save isaacarroyov/a03a58fe79dd6657eead2966fe7d65f3 to your computer and use it in GitHub Desktop.
application of the silhouette method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import silhouette_samples, silhouette_score | |
#create a list of K-Means models. Each element is a KMeans model with a specific number of clusters | |
kmeans2_sil= [KMeans(n_clusters=i, random_state=11, init='k-means++').fit(df_standardized) for i in range(1,15)] | |
#calculamos el silhouette score a cada modelo (de diferente número de clusters) | |
sil_values = [ silhouette_score(df_standardized, model.labels_, random_state=11) | |
for model in kmeans2_sil[1:] | |
] | |
#save the silhouette coefficient in an array | |
sil_values = np.array( sil_values ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment