Skip to content

Commit

Permalink
KMeansCorrelationHeuristic: KMeans uses n_init=1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markotoplak committed Nov 27, 2023
1 parent bf2219d commit 8351d7f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Orange/widgets/data/owcorrelations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/data/tests/test_owcorrelations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8351d7f

Please sign in to comment.