Skip to content

KBinsDiscretizer efficiency improvement to 'kmeans' strategy #19934

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 4 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whats_new/v1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ Changelog
supporting sparse matrix and raise the appropriate error message.
:pr:`19879` by :user:`Guillaume Lemaitre <glemaitre>`.

- |Efficiency| Changed ``algorithm`` argument for :class:`cluster.KMeans` in
:class:`preprocessing.KBinsDiscretizer` from ``auto`` to ``full``.
:pr:`19934` by :user:`Gleb Levitskiy <GLevV>`.

:mod:`sklearn.tree`
...................

Expand Down
3 changes: 2 additions & 1 deletion sklearn/preprocessing/_discretization.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def fit(self, X, y=None):
init = (uniform_edges[1:] + uniform_edges[:-1])[:, None] * 0.5

# 1D k-means procedure
km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1)
km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1,
algorithm='full')
centers = km.fit(column[:, None]).cluster_centers_[:, 0]
# Must sort, centers may be unsorted even with sorted init
centers.sort()
Expand Down