|
15 | 15 | from sklearn.exceptions import ConvergenceWarning, NotFittedError
|
16 | 16 | from sklearn.metrics import euclidean_distances
|
17 | 17 | from sklearn.utils._testing import assert_allclose, assert_array_equal
|
| 18 | +from sklearn.utils.fixes import CSR_CONTAINERS |
18 | 19 |
|
19 | 20 | n_clusters = 3
|
20 | 21 | centers = np.array([[1, 1], [-1, -1], [1, -1]]) + 10
|
@@ -104,10 +105,11 @@ def test_affinity_propagation_affinity_shape():
|
104 | 105 | affinity_propagation(S[:, :-1])
|
105 | 106 |
|
106 | 107 |
|
107 |
| -def test_affinity_propagation_precomputed_with_sparse_input(): |
| 108 | +@pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 109 | +def test_affinity_propagation_precomputed_with_sparse_input(csr_container): |
108 | 110 | err_msg = "A sparse matrix was passed, but dense data is required"
|
109 | 111 | with pytest.raises(TypeError, match=err_msg):
|
110 |
| - AffinityPropagation(affinity="precomputed").fit(csr_matrix((3, 3))) |
| 112 | + AffinityPropagation(affinity="precomputed").fit(csr_container((3, 3))) |
111 | 113 |
|
112 | 114 |
|
113 | 115 | def test_affinity_propagation_predict(global_random_seed, global_dtype):
|
@@ -287,20 +289,22 @@ def test_correct_clusters(global_dtype):
|
287 | 289 | assert_array_equal(afp.labels_, expected)
|
288 | 290 |
|
289 | 291 |
|
290 |
| -def test_sparse_input_for_predict(): |
| 292 | +@pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 293 | +def test_sparse_input_for_predict(csr_container): |
291 | 294 | # Test to make sure sparse inputs are accepted for predict
|
292 | 295 | # (non-regression test for issue #20049)
|
293 | 296 | af = AffinityPropagation(affinity="euclidean", random_state=42)
|
294 | 297 | af.fit(X)
|
295 |
| - labels = af.predict(csr_matrix((2, 2))) |
| 298 | + labels = af.predict(csr_container((2, 2))) |
296 | 299 | assert_array_equal(labels, (2, 2))
|
297 | 300 |
|
298 | 301 |
|
299 |
| -def test_sparse_input_for_fit_predict(): |
| 302 | +@pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 303 | +def test_sparse_input_for_fit_predict(csr_container): |
300 | 304 | # Test to make sure sparse inputs are accepted for fit_predict
|
301 | 305 | # (non-regression test for issue #20049)
|
302 | 306 | af = AffinityPropagation(affinity="euclidean", random_state=42)
|
303 | 307 | rng = np.random.RandomState(42)
|
304 |
| - X = csr_matrix(rng.randint(0, 2, size=(5, 5))) |
| 308 | + X = csr_container(rng.randint(0, 2, size=(5, 5))) |
305 | 309 | labels = af.fit_predict(X)
|
306 | 310 | assert_array_equal(labels, (0, 1, 1, 2, 3))
|
0 commit comments