Skip to content

Commit a58ac8c

Browse files
committed
TST: add a test for empty reassignment in MBKmeans
1 parent 60b3181 commit a58ac8c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sklearn/cluster/tests/test_k_means.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,22 @@ def test_minibatch_reassign():
344344
assert_greater(((centers_before - centers_after)**2).sum(axis=1).min(),
345345
.2)
346346

347+
# Give a perfect initialization, with a small reassignment_ratio,
348+
# no center should be reassigned
349+
for this_X in (X, X_csr):
350+
mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, batch_size=1,
351+
init=centers.copy(),
352+
random_state=42)
353+
mb_k_means.fit(this_X)
354+
centers_before = mb_k_means.cluster_centers_.copy()
355+
# Turn on verbosity to smoke test the display code
356+
_mini_batch_step(this_X, (X ** 2).sum(axis=1),
357+
mb_k_means.cluster_centers_,
358+
mb_k_means.counts_,
359+
np.zeros(X.shape[1], np.double),
360+
False, random_reassign=True, random_state=42,
361+
reassignment_ratio=1e-15)
362+
347363

348364
def test_sparse_mb_k_means_callable_init():
349365

0 commit comments

Comments
 (0)