Skip to content

Commit 16244a0

Browse files
committed
BUG: sparse center reassignment MiniBatchKMeans
1 parent 68d2388 commit 16244a0

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

sklearn/cluster/k_means_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def _mini_batch_step(X, x_squared_norms, centers, counts,
869869
if n_reassigns:
870870
print("[_mini_batch_step] Reassigning %i cluster centers."
871871
% n_reassigns)
872-
centers[to_reassign] = new_centers
872+
centers[to_reassign] = new_centers.toarray()
873873

874874
# implementation for the sparse CSR reprensation completely written in
875875
# cython

sklearn/cluster/tests/test_k_means.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,8 @@ def test_minibatch_reassign():
323323
# as a result all the centers should be reassigned and the model
324324
# should not longer be good
325325
for this_X in (X, X_csr):
326-
mb_k_means = MiniBatchKMeans(init=centers.copy(),
327-
n_clusters=n_clusters, batch_size=1,
328-
random_state=42)
326+
mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, batch_size=1,
327+
random_state=42)
329328
mb_k_means.fit(X)
330329
centers_before = mb_k_means.cluster_centers_.copy()
331330
try:

0 commit comments

Comments
 (0)