FIX Elkan k-means does not stop if tol=0#16075
Merged
rth merged 3 commits intoscikit-learn:masterfrom Feb 5, 2020
Merged
Conversation
jeremiedbb
approved these changes
Jan 14, 2020
Member
jeremiedbb
left a comment
There was a problem hiding this comment.
lgtm. Please add a what's new entry.
981e933 to
7c22fdf
Compare
Contributor
Author
|
Extended a unit test that failed before my change (300 vs. 7 iterations; simply by adding |
rth
approved these changes
Feb 5, 2020
Member
rth
left a comment
There was a problem hiding this comment.
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.
Contributor
Author
|
Re-triggered CI, checks passed. |
Member
|
Thanks @kno10 ! |
6 tasks
thomasjpfan
pushed a commit
to thomasjpfan/scikit-learn
that referenced
this pull request
Feb 22, 2020
panpiort8
pushed a commit
to panpiort8/scikit-learn
that referenced
this pull request
Mar 3, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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=0this means that "full" may stop when the clusters stop moving, while withelkanit 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.