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

Skip to content

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)


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