[scikit-learn] Issues with kmeans: Difference in centroid values

Sidak Pal Singh spssachdeva21695 at gmail.com
Mon Apr 16 16:07:03 EDT 2018


Hi everyone,

I was using scikit-learn KMeans algorithm to cluster pretrained
word-vectors. There are a few things which I found to be surprising and
wanted to get some feedback on.

- Based upon the 'labels_' assigned to each word-vector (i.e. cluster
memberships), I compute every cluster centroid as the average of the
word-vectors (corresponding to that cluster). Surprisingly, this seems to
be pretty different from the 'cluster_centers_'. Is there anything that I
am missing here?

- I was later using the verbose option to see if the clustering has
converged or not. I saw on the console log messages such as *"**center
shift 7.994126e-04 within tolerance 1.243425e-06"*. It seems that this
corresponds to some code in *kmeans_elkan.pyx* (
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/cluster/_k_means_elkan.pyx
).

- Lastly, another thing that seems strange is that I hadn't set the
tolerance value. So the default of 1e-4 should have been used. But if you
look again at the above log, it says *within tolerance 1.243425e-06 instead
of 1e-4. *

It would be great if you can look into this and help me out.

Thank you so much! :)

Best,
Sidak Pal Singh
EPFL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20180416/28ef6341/attachment.html>


More information about the scikit-learn mailing list