|
4 | 4 | import numpy as np
|
5 | 5 | import pytest
|
6 | 6 | from numpy.testing import assert_array_equal
|
7 |
| -from scipy import sparse as sp |
8 | 7 |
|
9 | 8 | from sklearn import datasets
|
10 | 9 | from sklearn.neighbors import NearestCentroid
|
| 10 | +from sklearn.utils.fixes import CSR_CONTAINERS |
11 | 11 |
|
12 | 12 | # toy sample
|
13 | 13 | X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]
|
14 |
| -X_csr = sp.csr_matrix(X) # Sparse matrix |
15 | 14 | y = [-1, -1, -1, 1, 1, 1]
|
16 | 15 | T = [[-1, -1], [2, 2], [3, 2]]
|
17 |
| -T_csr = sp.csr_matrix(T) |
18 | 16 | true_result = [-1, 1, 1]
|
19 | 17 |
|
20 | 18 | # also load the iris dataset
|
|
26 | 24 | iris.target = iris.target[perm]
|
27 | 25 |
|
28 | 26 |
|
29 |
| -def test_classification_toy(): |
| 27 | +@pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 28 | +def test_classification_toy(csr_container): |
30 | 29 | # Check classification on a toy dataset, including sparse versions.
|
| 30 | + X_csr = csr_container(X) |
| 31 | + T_csr = csr_container(T) |
| 32 | + |
31 | 33 | clf = NearestCentroid()
|
32 | 34 | clf.fit(X, y)
|
33 | 35 | assert_array_equal(clf.predict(T), true_result)
|
@@ -135,8 +137,10 @@ def test_predict_translated_data():
|
135 | 137 | assert_array_equal(y_init, y_translate)
|
136 | 138 |
|
137 | 139 |
|
138 |
| -def test_manhattan_metric(): |
| 140 | +@pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 141 | +def test_manhattan_metric(csr_container): |
139 | 142 | # Test the manhattan metric.
|
| 143 | + X_csr = csr_container(X) |
140 | 144 |
|
141 | 145 | clf = NearestCentroid(metric="manhattan")
|
142 | 146 | clf.fit(X, y)
|
|
0 commit comments