Skip to content

Commit 044c321

Browse files
committed
owkmeans: fix initialization choice
1 parent 3f4b423 commit 044c321

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Orange/widgets/unsupervised/owkmeans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def __launch_tasks(self, ks):
316316
self._compute_clustering,
317317
data=self.data,
318318
k=k,
319-
init=['random', 'k-means++'][self.smart_init],
319+
init=['k-means++', 'random'][self.smart_init],
320320
n_init=self.n_init,
321321
max_iter=self.max_iterations,
322322
silhouette=True,

Orange/widgets/unsupervised/tests/test_owkmeans.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@ def test_do_not_recluster_on_same_data(self):
411411
self.commit_and_wait()
412412
self.assertEqual(call_count + 1, commit.call_count)
413413

414+
def test_correct_smart_init(self):
415+
# due to a bug where wrong init was passed to _compute_clustering
416+
self.send_signal(self.widget.Inputs.data, self.iris[::10], wait=5000)
417+
self.widget.smart_init = 0
418+
with patch.object(self.widget, "_compute_clustering",
419+
wraps=self.widget._compute_clustering) as compute:
420+
self.commit_and_wait()
421+
self.assertEqual(compute.call_args[1]['init'], "k-means++")
422+
self.widget.invalidate() # reset caches
423+
self.widget.smart_init = 1
424+
with patch.object(self.widget, "_compute_clustering",
425+
wraps=self.widget._compute_clustering) as compute:
426+
self.commit_and_wait()
427+
self.assertEqual(compute.call_args[1]['init'], "random")
428+
414429

415430
if __name__ == "__main__":
416431
unittest.main()

0 commit comments

Comments
 (0)