Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MNT Refactor center initialization in KMeans #17928

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

Merged
merged 2 commits into from
Jul 17, 2020

Conversation

jeremiedbb
Copy link
Member

@jeremiedbb jeremiedbb commented Jul 15, 2020

Make the center initialization in a single place, i.e in fit.
Avoid repeated validations.
Make _init_centroids a method KMeans to make cleaner use of KMeans attributes.

Extracted from #17622 to facilitate the reviews.

ping @glemaitre

Squared euclidean norm of each data point. Pass it if you have it
at hands already to avoid it being recomputed here.

init : {'k-means++', 'random', ndarray, callable}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
init : {'k-means++', 'random', ndarray, callable}
init : {'k-means++', 'random'}, callable or ndarray of shape (n_clusters, n_features)

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM


Returns
-------
centers : ndarray of shape(n_clusters, n_features)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
centers : ndarray of shape(n_clusters, n_features)
centers : ndarray of shape (n_clusters, n_features)

@@ -624,7 +554,6 @@ def _labels_inertia(X, sample_weight, x_squared_norms, centers,

n_threads = _openmp_effective_n_threads(n_threads)

sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

This has been done in the main method (fit, predict, etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. The goal is to do all validations in the fit, predict, etc methods and have all private helpers assume validation is already done, to avoid duplicating validation

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

@thomasjpfan thomasjpfan merged commit 1296fc0 into scikit-learn:master Jul 17, 2020
jayzed82 pushed a commit to jayzed82/scikit-learn that referenced this pull request Oct 22, 2020
* refactor center init in KMeans

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

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.