From f3256892cf11aef8f53905d2974cccd0450c1766 Mon Sep 17 00:00:00 2001 From: Joel Nothman Date: Tue, 30 Apr 2019 18:35:54 +1000 Subject: [PATCH 1/2] TST do not test fit determinism together with predict/labels_ equality --- sklearn/cluster/tests/test_k_means.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sklearn/cluster/tests/test_k_means.py b/sklearn/cluster/tests/test_k_means.py index 4d1e517742b3e..25982060baf6d 100644 --- a/sklearn/cluster/tests/test_k_means.py +++ b/sklearn/cluster/tests/test_k_means.py @@ -342,10 +342,12 @@ def test_k_means_fit_predict(algo, dtype, constructor, seed, max_iter, tol): kmeans = KMeans(algorithm=algo, n_clusters=10, random_state=seed, tol=tol, max_iter=max_iter, n_jobs=1) - labels_1 = kmeans.fit(X).predict(X) - labels_2 = kmeans.fit_predict(X) + labels_1 = kmeans.fit_predict(X) + labels_2 = kmeans.predict(X) + labels_3 = kmeans.labels_ assert_array_equal(labels_1, labels_2) + assert_array_equal(labels_1, labels_3) def test_mb_kmeans_verbose(): From b2a63471ae107945e97645946e83b081933c8576 Mon Sep 17 00:00:00 2001 From: Joel Nothman Date: Tue, 30 Apr 2019 20:38:46 +1000 Subject: [PATCH 2/2] Fix comment --- sklearn/cluster/tests/test_k_means.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/cluster/tests/test_k_means.py b/sklearn/cluster/tests/test_k_means.py index 25982060baf6d..9d283a597ef6d 100644 --- a/sklearn/cluster/tests/test_k_means.py +++ b/sklearn/cluster/tests/test_k_means.py @@ -328,7 +328,7 @@ def test_k_means_fortran_aligned_data(): (4, 300, 1e-1), # loose convergence ]) def test_k_means_fit_predict(algo, dtype, constructor, seed, max_iter, tol): - # check that fit.predict gives same result as fit_predict + # check that predict gives same result as fit_predict or labels_ # There's a very small chance of failure with elkan on unstructured dataset # because predict method uses fast euclidean distances computation which # may cause small numerical instabilities.