From 5bc1328d4d7f3a99d766f59436965f1f74ff4cf9 Mon Sep 17 00:00:00 2001 From: Dante Gama Dessavre Date: Thu, 19 Dec 2024 19:04:20 -0600 Subject: [PATCH] Adjust test_kmeans to avoid false positive failures (#6193) Before this, we would fail when cuML KMeans achieved a better score than scikit-learn by the margin. Authors: - Dante Gama Dessavre (https://github.com/dantegd) Approvers: - William Hicks (https://github.com/wphicks) URL: https://github.com/rapidsai/cuml/pull/6193 --- python/cuml/cuml/tests/test_kmeans.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/cuml/cuml/tests/test_kmeans.py b/python/cuml/cuml/tests/test_kmeans.py index b05a762177..ec5a2e0a3a 100644 --- a/python/cuml/cuml/tests/test_kmeans.py +++ b/python/cuml/cuml/tests/test_kmeans.py @@ -171,7 +171,7 @@ def test_weighted_kmeans(nrows, ncols, nclusters, max_weight, random_state): sk_kmeans.fit(cp.asnumpy(X), sample_weight=wt) sk_score = sk_kmeans.score(cp.asnumpy(X)) - assert abs(cu_score - sk_score) <= cluster_std * 1.5 + assert cu_score - sk_score <= cluster_std * 1.5 @pytest.mark.parametrize("nrows", [1000, 10000]) @@ -418,5 +418,6 @@ def test_fit_transform_weighted_kmeans( sk_transf = sk_kmeans.fit_transform(cp.asnumpy(X), sample_weight=wt) sk_score = sk_kmeans.score(cp.asnumpy(X)) - assert abs(cu_score - sk_score) <= cluster_std * 1.5 + # we fail if cuML's score is significantly worse than sklearn's + assert cu_score - sk_score <= cluster_std * 1.5 assert sk_transf.shape == cuml_transf.shape