Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the k_means_clust function has a error #7

Open
kylinLiu opened this issue Aug 10, 2017 · 2 comments
Open

the k_means_clust function has a error #7

kylinLiu opened this issue Aug 10, 2017 · 2 comments

Comments

@kylinLiu
Copy link

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)
@poweihuang17
Copy link

Thank you for pointing it out!

@DMTSource
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants