Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST test_k_means_fit_predict: do not test fit determinism together with predict/labels_ equality #13751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions sklearn/cluster/tests/test_k_means.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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():
Expand Down