time-series-classification-and-clustering
time-series-classification-and-clustering copied to clipboard
Error while recalculate centroids of clusters(int is not iterable)
#recalculate centroids of clusters
for key in self.assignments:
clust_sum=0
for k in self.assignments[key]:
clust_sum=clust_sum+data[k]
self.centroids[key]=[m/len(self.assignments[key]) for m in clust_sum]-- error in this line,int is not iterable.
change clust_sum declaration to np.zeros(len(data[0])) change clust_sum=clust_sum+data[k] to clust_sum=np.add(clust_sum,data[k])
change it to following code
#recalculate centroids of clusters for key in self.assignments: clust_sum=np.zeros(len(data[0])) for k in self.assignments[key]: clust_sum=np.add(clust_sum,data[k]) self.centroids[key]=[m/len(self.assignments[key]) for m in clust_sum]
Hey, how to deal with variable length items in data?
Thanks for pointing out this error!