From 8351d7f3069ab53c9c2bc15bfb1a8e4ed1fcdbdb Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Mon, 27 Nov 2023 13:25:11 +0100 Subject: [PATCH] KMeansCorrelationHeuristic: KMeans uses n_init=1 Default values of KMeans change in scikit-learn 1.4. I adapted a failing test (and code) for the new default. From the reference: When n_init='auto', the number of runs depends on the value of init: 10 if using init='random' or init is a callable; 1 if using init='k-means++' or init is an array-like. Changed in version 1.4: Default value for n_init will change from 10 to 'auto' in version 1.4. --- Orange/widgets/data/owcorrelations.py | 2 +- Orange/widgets/data/tests/test_owcorrelations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Orange/widgets/data/owcorrelations.py b/Orange/widgets/data/owcorrelations.py index 4779ad8a866..b1e96922863 100644 --- a/Orange/widgets/data/owcorrelations.py +++ b/Orange/widgets/data/owcorrelations.py @@ -70,7 +70,7 @@ def get_clusters_of_attributes(self): :return: generator of attributes grouped by cluster """ data = Normalize()(self.data).X.T - kmeans = KMeans(n_clusters=self.n_clusters, random_state=0).fit(data) + kmeans = KMeans(n_clusters=self.n_clusters, random_state=0, n_init=1).fit(data) labels_attrs = sorted([(l, i) for i, l in enumerate(kmeans.labels_)]) return [Cluster(instances=list(pair[1] for pair in group), centroid=kmeans.cluster_centers_[l]) diff --git a/Orange/widgets/data/tests/test_owcorrelations.py b/Orange/widgets/data/tests/test_owcorrelations.py index f8b31b15703..17b7bd4f9a0 100644 --- a/Orange/widgets/data/tests/test_owcorrelations.py +++ b/Orange/widgets/data/tests/test_owcorrelations.py @@ -362,7 +362,7 @@ def test_get_clusters_of_attributes(self): clusters = self.heuristic.get_clusters_of_attributes() # results depend on scikit-learn k-means implementation result = sorted([c.instances for c in clusters]) - self.assertListEqual([[0], [1, 2, 3, 4, 5, 6, 7], [8]], + self.assertListEqual([[0, 3, 5], [1, 2, 6, 7], [4, 8]], result) def test_get_states(self):