-
-
Notifications
You must be signed in to change notification settings - Fork 25.5k
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
FIX Elkan k-means does not stop if tol=0 #16075
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Please add a what's new entry.
981e933
to
7c22fdf
Compare
Extended a unit test that failed before my change (300 vs. 7 iterations; simply by adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add an empty commit to re-trigger CI (git commit --allow-empty
)?
The existing failing build fails to load so I don't know if it could be related. Otherwise LGTM.
Re-triggered CI, checks passed. |
Thanks @kno10 ! |
K-means convergence is still different between "full" k-means and "elkan" k-means.
The fix in #15831 is incomplete. Compare:
scikit-learn/sklearn/cluster/_kmeans.py
Lines 441 to 442 in 4fe4d27
and
scikit-learn/sklearn/cluster/_k_means_elkan.pyx
Line 233 in 4fe4d27
scikit-learn/sklearn/cluster/_k_means_elkan.pyx
Lines 249 to 250 in 4fe4d27
it should be noted that in the second version, it would likely make sense to first use
squared_norm
, and then separate the square root, rather than taking the square of the rooted values below.But in this PR I'm just pointing to a single character. One tests
<=
and the other tests<
.With
tol=0
this means that "full" may stop when the clusters stop moving, while withelkan
it never stops then, but always takes all iterations.I do not think this is the best stopping criterion. If a numerical issue arises in computing the center shifts, this may cause the algorithm to always take the maximum number of iterations. The classic termination criterion for k-means is different: stop if no object is relabeled. That is more reliable.