I am trying to figure out the optimum number of clusters using various clustering performance evaluation methods. I put my data through a loop and ran DBA k-means. I am getting the elbow and silhouette results but the dunn index is showing error. Below is the code:
inertias = []
silhouette = []
davies_bouldin = []
clusters_range = range(1, 10)
for K in clusters_range:
dba_km = TimeSeriesKMeans(n_clusters=K,
n_init=2,
metric="dtw",
verbose=True,
max_iter_barycenter=10,
random_state=seed)
y_pred = dba_km.fit_predict(scaled_ts)
inertias.append(dba_km.inertia_)
if K > 1:
silhouette.append(silhouette_score(scaled_ts, dba_km.labels_))
davies_bouldin.append(davies_bouldin_score(scaled_ts, dba_km.labels_))
The error is showing on the davies_bouldin.append
line:
TypeError: 'list' object is not callable.
this is my first post here: I'm still quite an amateur in python, so I came here looking for some answers myself and found your post. Turns out I've used your code to do something similar, with just a couple of minor adjustments and it worked perfectly! let me show you my adaptation:
wcss = []
sil_score = []
db_score = []
clusters_range = range(2, 16)
for K in clusters_range:
kmeans = KMeans(n_clusters = K, max_iter = 300)
kmeans.fit_predict(X2_pca_df)
wcss.append(kmeans.inertia_)
sil_score.append(silhouette_score(X2_pca_df, kmeans.labels_))
db_score.append(davies_bouldin_score(X2_pca_df, kmeans.labels_))
Ps. Not sure when you posted this one, but hope it's not to late to give a hand. Cheers!