diff --git a/sklearn/cluster/_kmeans.py b/sklearn/cluster/_kmeans.py index 8b24be6ace987..07a3496517f1a 100644 --- a/sklearn/cluster/_kmeans.py +++ b/sklearn/cluster/_kmeans.py @@ -1057,7 +1057,9 @@ def fit(self, X, y=None, sample_weight=None): x_squared_norms=x_squared_norms, n_threads=self._n_threads) # determine if these results are the best so far - if best_inertia is None or inertia < best_inertia: + # allow small tolerance on the inertia to accommodate for + # non-deterministic rounding errors due to parallel computation + if best_inertia is None or inertia < best_inertia * (1 - 1e-6): best_labels = labels best_centers = centers best_inertia = inertia