8000 TST Extend tests for `scipy.sparse.*array` in `sklearn/svm/tests/test… · scikit-learn/scikit-learn@bb58543 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb58543

Browse files
authored
TST Extend tests for scipy.sparse.*array in sklearn/svm/tests/test_svm.py (#27128)
1 parent 1a9c006 commit bb58543

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

sklearn/svm/tests/test_svm.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
assert_array_almost_equal,
1515
assert_array_equal,
1616
)
17-
from scipy import sparse
1817

1918
from sklearn import base, datasets, linear_model, metrics, svm
2019
from sklearn.datasets import make_blobs, make_classification
@@ -40,6 +39,7 @@
4039
from sklearn.svm._classes import _validate_dual_parameter
4140
from sklearn.utils import check_random_state, shuffle
4241
from sklearn.utils._testing import ignore_warnings
42+
from sklearn.utils.fixes import CSR_CONTAINERS, LIL_CONTAINERS
4343
from sklearn.utils.validation import _num_samples
4444

4545
# toy sample
@@ -682,7 +682,8 @@ def test_auto_weight():
682682
)
683683

684684

685-
def test_bad_input():
685+
@pytest.mark.parametrize("lil_container", LIL_CONTAINERS)
686+
def test_bad_input(lil_container):
686687
# Test dimensions for labels
687688
Y2 = Y[:-1] # wrong dimensions for labels
688689
with pytest.raises(ValueError):
@@ -707,7 +708,7 @@ def test_bad_input():
707708
# predict with sparse input when trained with dense
708709
clf = svm.SVC().fit(X, Y)
709710
with pytest.raises(ValueError):
710-
clf.predict(sparse.lil_matrix(X))
711+
clf.predict(lil_container(X))
711712

712713
Xt = np.array(X).T
713714
clf.fit(np.dot(X, Xt), Y)
@@ -744,18 +745,18 @@ def test_unicode_kernel():
744745
)
745746

746747

747-
def test_sparse_precomputed():
748+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
749+
def test_sparse_precomputed(csr_container):
748750
clf = svm.SVC(kernel="precomputed")
749-
sparse_gram = sparse.csr_matrix([[1, 0], [0, 1]])
751+
sparse_gram = csr_container([[1, 0], [0, 1]])
750752
with pytest.raises(TypeError, match="Sparse precomputed"):
751753
clf.fit(sparse_gram, [0, 1])
752754

753755

754-
def test_sparse_fit_support_vectors_empty():
756+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
757+
def test_sparse_fit_support_vectors_empty(csr_container):
755758
# Regression test for #14893
756-
X_train = sparse.csr_matrix(
757-
[[0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]
758-
)
759+
X_train = csr_container([[0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]])
759760
y_train = np.array([0.04, 0.04, 0.10, 0.16])
760761
model = svm.SVR(kernel="linear")
761762
model.fit(X_train, y_train)

0 commit comments

Comments
 (0)
0