Find the centroid of a cluster in tslearn soft-dtw / dtw clustering

Viewed 49

I'm using tslearn to perform time-series clustering. I was trying to find out what I should do if I want to find the centroid of each cluster but had no luck so far. The document mentioned a "barycenter" that sounds like the centroid to me, but it didn't say how to calculate the barycenter. Does anyone happen to have experience in this area? Thanks! Below is the code I use so far to do the clustering work.

for j in [2,3]: # try 2 and 3 clusters 
    km = TimeSeriesKMeans(n_clusters=j, metric="softdtw")
    labels = km.fit_predict(ts_intention_list)
    silhouetteScore = silhouette_score(ts_intention_list, labels, metric="softdtw")
    print(f"\nLabels for {j} clusters: {labels}")

    num_of_clusters_list.append(j)
    silhouetteScore_list.append(silhouetteScore)
    print(f"{j} clusters, score is {silhouetteScore}")
0 Answers
Related