8000 More stable n_init runs for KMeans (#20200) · samronsin/scikit-learn@9912dbb · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 9912dbb

Browse files
jeremiedbbsamronsin
authored andcommitted
More stable n_init runs for KMeans (scikit-learn#20200)
1 parent 8fa4e48 commit 9912dbb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sklearn/cluster/_kmeans.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,9 @@ def fit(self, X, y=None, sample_weight=None):
11891189
)
11901190

11911191
# determine if these results are the best so far
1192-
if best_inertia is None or inertia < best_inertia:
1192+
# allow small tolerance on the inertia to accommodate for
1193+
# non-deterministic rounding errors due to parallel computation
1194+
if best_inertia is None or inertia < best_inertia * (1 - 1e-6):
11931195
best_labels = labels
11941196
best_centers = centers
11951197
best_inertia = inertia

0 commit comments

Comments
 (0)
0