Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@thomasjpfan
Copy link
Member

Reference Issues/PRs

Fixes #24253

What does this implement/fix? Explain your changes.

This PR allows for the attributes for KMeans to be read-only. When update_centers=False, lloyd_iter_chunked_dense does not actually update centers_new. This is the case when KMeans.predict ends up calling _labels_inertia:

update_centers=False,

Any other comments?

Side note: I think the new test in this PR for read only attributes can become a common test.

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix.

Can you please just update the docstrings of lloyd_iter_chunked_dense and lloyd_iter_chunked_sparse to make it explicit that centers_new and centers_squared_norms can be left to None if update_centers is False?

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to give my approval instead of just a comment in the above review.

@ogrisel ogrisel added the Quick Review For PRs that are quick to review label Aug 25, 2022
@ogrisel
Copy link
Member

ogrisel commented Aug 25, 2022

@jjerphan @jeremiedbb or @fcharras might be interested in giving this PR a second look.

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for fixing this issue.

Side note: I think the new test in this PR for read only attributes can become a common test.

I am OK making the test a common test. IMO, this can be done as part of this PR.

Side note: we recently discovered that some part of the routines can be simplified, see: #24262

Co-authored-by: Julien Jerphanion <[email protected]>
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well after this comment #24258 (review) is addressed

@thomasjpfan
Copy link
Member Author

Updated PR with:

@jjerphan jjerphan merged commit b34edd3 into scikit-learn:main Sep 2, 2022
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cython module:cluster Quick Review For PRs that are quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KMeans predict method fails when run in ray remote function due to in-place modification of cluster_centers_ attribute

4 participants