Skip to content

Commit 94d3bd4

Browse files
committed
MISC: <= rather than < in tol check (KMeans)
As reported by @EdwardRaff in scikit-learn#3374
1 parent 5727099 commit 94d3bd4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sklearn/cluster/k_means_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _kmeans_single(X, n_clusters, x_squared_norms, max_iter=300,
391391
best_centers = centers.copy()
392392
best_inertia = inertia
393393

394-
if np.sum((centers_old - centers) ** 2) < tol:
394+
if np.sum((centers_old - centers) ** 2) <= tol:
395395
if verbose:
396396
print("Converged at iteration %d" % i)
397397
break
@@ -981,7 +981,7 @@ def _mini_batch_convergence(model, iteration_idx, n_iter, tol,
981981

982982
# Early stopping based on absolute tolerance on squared change of
983983
# centers position (using EWA smoothing)
984-
if tol > 0.0 and ewa_diff < tol:
984+
if tol > 0.0 and ewa_diff <= tol:
985985
if verbose:
986986
print('Converged (small centers change) at iteration %d/%d'
987987
% (iteration_idx + 1, n_iter))

0 commit comments

Comments
 (0)