Skip to content

Commit 433a381

Browse files
committed
FIX: broken HMM tests caused by KMeans convergence in one step
1 parent 231057b commit 433a381

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sklearn/cluster/k_means_.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,16 @@ def k_means(X, k, init='k-means++', n_init=10, max_iter=300, verbose=0,
244244
if verbose:
245245
print 'Iteration %i, inertia %s' % (i, inertia)
246246

247+
if best_inertia is None or inertia < best_inertia:
248+
best_labels = labels.copy()
249+
best_centers = centers.copy()
250+
best_inertia = inertia
251+
247252
if np.sum((centers_old - centers) ** 2) < tol * vdata:
248253
if verbose:
249254
print 'Converged to similar centers at iteration', i
250255
break
251256

252-
if best_labels is None or inertia < best_inertia:
253-
best_labels = labels.copy()
254-
best_centers = centers.copy()
255-
best_inertia = inertia
256257

257258
if not copy_x:
258259
X += X_mean

0 commit comments

Comments
 (0)