def clustering_algorithm(n_clusters, dataset):
kmeans = KMeans(n_clusters=n_clusters, n_init=10, max_iter=300) # Kmeans
labels = kmeans.fit_predict(dataset) # labels
s = metrics.silhouette_score(dataset, labels, metric='euclidean') # Silhouette
dbs = metrics.davies_bouldin_score(dataset, labels) # Davies-Bouldin
calinski = metrics.calinski_harabasz_score(dataset, labels) # Calinski
print(f'|{n_clusters}| CLUSTERS:\nSilhouette: {s:.3f}\nDavies-Bouldin: {dbs:.3f}\nCalinski: {calinski:.3f}')
return s, dbs, calinski
for n in range(2,11):
clustering_algorithm(n, values)
print('-'*30)
Melhor resultado:
|6| CLUSTERS
Silhouette: 0.365
Davies-Bouldin: 1.045
Calinski: 3523.512