8000 ENH Avoid repeated input checks in kmeans++ by jeremiedbb · Pull Request #19002 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

ENH Avoid repeated input checks in kmeans++ #19002

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 11 commits into from
Dec 20, 2020

Conversation

jeremiedbb
Copy link
Member
@jeremiedbb jeremiedbb commented Dec 14, 2020

kmeans++ calls euclidean_distances many times and each call repeat the check of the input which is not necessary since it has already been checked.

partially take over #7383

The time wasted in the input check can be huge on machines with many cores. For instance I tested on a machine with 44 cores. Here's the time spent during KMeans.fit (in seconds):

master PR
total time 252 165
in kmeans++ 166 79
in lloyd 83 84

cc @ogrisel

@jeremiedbb
Copy link
Member Author

Future improvement could be to merge the computation of the euclidean distances with the computation of the min in a single function parallelized over data chunks in cython (a bit like it's done for the kmeans iteration loop. In fact maybe some part of the code could be shared).

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.

This looks great. This is a nice and simple perf improvement.

@ogrisel
Copy link
Member
ogrisel commented Dec 16, 2020

Please document it in whats new (for 1.0 as suppose as the previous perf was not catastrophic enough to be considered a bug).

Although, since 0.24.0 is not yet out we could also consider it for inclusion in 0.24.0, as you wish.

@ogrisel
Copy link
Member
ogrisel commented Dec 16, 2020

For reference, I made a summary of our current understanding of the perf issues with k-means++ init in #10924 (comment).

@jeremiedbb jeremiedbb changed the title [WIP] Avoid repeated input checks in kmeans++ [MRG] Avoid repeated input checks in kmeans++ Dec 16, 2020
@ogrisel ogrisel requested a review from thomasjpfan December 16, 2020 14:31
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.

The simplification in _euclidean_distances is quite nice.

Minor comments, otherwise LGTM

jeremiedbb and others added 2 commits December 19, 2020 13:43
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
8000
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
@thomasjpfan thomasjpfan changed the title [MRG] Avoid repeated input checks in kmeans++ ENH Avoid repeated input checks in kmeans++ Dec 20, 2020
@thomasjpfan thomasjpfan merged commit dc1ea27 into scikit-learn:master Dec 20, 2020
@glemaitre glemaitre mentioned this pull request Dec 22, 2020
14 tasks
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
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
0