time-series-classification-and-clustering
time-series-classification-and-clustering copied to clipboard
the k_means_clust function has a error
if closest_clust in assignments:
assignments[closest_clust].append(ind)
else:
assignments[closest_clust]=[]
this code is error! when the element match the clus , the element will not append to the clust ,it make the result error!the right code like this:
assignments.setdefault(closest_clust,[])
assignments[closest_clust].append(ind)
Thank you for pointing it out!
Thank you, this fixes the frequent error of trying to assign an oddly empty assignment to a centroid(clust_sum was still 0 at time of iteration) on line 47 of ts_cluster.py: https://github.com/alexminnaar/time-series-classification-and-clustering/blob/master/clustering/ts_cluster.py#L47
In many cases I would randomly see this error; especially for cases of many clusters as assignments was more likely to have missed an update that your above fix addresses.
Traceback (most recent call last): File "study_clustering_based_selection.py", line 584, in
dtw_clustering(list(X), n_clusters) File "study_clustering_based_selection.py", line 549, in dtw_clustering tsc.k_means_clust(data=X, num_iter=3, w=5, progress=True) File "study_clustering_based_selection.py", line 223, in k_means_clust self.centroids[key]=[m/len(self.assignments[key]) for m in clust_sum] TypeError: 'int' object is not iterable