time-series-classification-and-clustering icon indicating copy to clipboard operation
time-series-classification-and-clustering copied to clipboard

Error while recalculate centroids of clusters(int is not iterable)

Open subramanya-sridhar opened this issue 8 years ago • 2 comments

    #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]

subramanya-sridhar avatar Dec 21 '16 13:12 subramanya-sridhar

Hey, how to deal with variable length items in data?

ewerlopes avatar Jan 28 '17 17:01 ewerlopes

Thanks for pointing out this error!

poweihuang17 avatar May 11 '18 03:05 poweihuang17