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

Commit ed37222

Browse filesBrowse files
committed
FIX BisectingKMeans crashes randomly (#25563)
Fixes #25505
1 parent dc61778 commit ed37222
Copy full SHA for ed37222

File tree

2 files changed

+10
-1
lines changed
Filter options

2 files changed

+10
-1
lines changed

‎doc/whats_new/v1.2.rst

Copy file name to clipboardExpand all lines: doc/whats_new/v1.2.rst
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ Changes impacting all modules
2727
Changelog
2828
---------
2929

30+
:mod:`sklearn.cluster`
31+
......................
32+
33+
- |Fix| Fixed a bug in :class:`cluster.BisectingKMeans`, preventing `fit` to randomly
34+
fail due to a permutation of the labels when running multiple inits.
35+
:pr:`25563` by :user:`Jérémie du Boisberranger <jeremiedbb>`.
36+
3037
:mod:`sklearn.isotonic`
3138
.......................
3239

‎sklearn/cluster/_bisect_k_means.py

Copy file name to clipboardExpand all lines: sklearn/cluster/_bisect_k_means.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ def _bisect(self, X, x_squared_norms, sample_weight, cluster_to_bisect):
337337
X, best_centers, best_labels, sample_weight
338338
)
339339
else: # bisecting_strategy == "largest_cluster"
340-
scores = np.bincount(best_labels)
340+
# Using minlength to make sure that we have the counts for both labels even
341+
# if all samples are labelled 0.
342+
scores = np.bincount(best_labels, minlength=2)
341343

342344
cluster_to_bisect.split(best_labels, best_centers, scores)
343345

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.