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 a4f4efe

Browse filesBrowse files
authored
TST Relax test_minibatch_sensible_reassign to avoid CI failures with single global random seed (#29278)
1 parent 65b2571 commit a4f4efe
Copy full SHA for a4f4efe

File tree

Expand file treeCollapse file tree

1 file changed

+6
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-3
lines changed

‎sklearn/cluster/tests/test_k_means.py

Copy file name to clipboardExpand all lines: sklearn/cluster/tests/test_k_means.py
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,21 +437,24 @@ def test_minibatch_sensible_reassign(global_random_seed):
437437
n_clusters=20, batch_size=10, random_state=global_random_seed, init="random"
438438
).fit(zeroed_X)
439439
# there should not be too many exact zero cluster centers
440-
assert km.cluster_centers_.any(axis=1).sum() > 10
440+
num_non_zero_clusters = km.cluster_centers_.any(axis=1).sum()
441+
assert num_non_zero_clusters > 9, f"{num_non_zero_clusters=} is too small"
441442

442443
# do the same with batch-size > X.shape[0] (regression test)
443444
km = MiniBatchKMeans(
444445
n_clusters=20, batch_size=200, random_state=global_random_seed, init="random"
445446
).fit(zeroed_X)
446447
# there should not be too many exact zero cluster centers
447-
assert km.cluster_centers_.any(axis=1).sum() > 10
448+
num_non_zero_clusters = km.cluster_centers_.any(axis=1).sum()
449+
assert num_non_zero_clusters > 9, f"{num_non_zero_clusters=} is too small"
448450

449451
# do the same with partial_fit API
450452
km = MiniBatchKMeans(n_clusters=20, random_state=global_random_seed, init="random")
451453
for i in range(100):
452454
km.partial_fit(zeroed_X)
453455
# there should not be too many exact zero cluster centers
454-
assert km.cluster_centers_.any(axis=1).sum() > 10
456+
num_non_zero_clusters = km.cluster_centers_.any(axis=1).sum()
457+
assert num_non_zero_clusters > 9, f"{num_non_zero_clusters=} is too small"
455458

456459

457460
@pytest.mark.parametrize(

0 commit comments

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