14
14
assert_array_almost_equal ,
15
15
assert_array_equal ,
16
16
)
17
- from scipy import sparse
18
17
19
18
from sklearn import base , datasets , linear_model , metrics , svm
20
19
from sklearn .datasets import make_blobs , make_classification
40
39
from sklearn .svm ._classes import _validate_dual_parameter
41
40
from sklearn .utils import check_random_state , shuffle
42
41
from sklearn .utils ._testing import ignore_warnings
42
+ from sklearn .utils .fixes import CSR_CONTAINERS , LIL_CONTAINERS
43
43
from sklearn .utils .validation import _num_samples
44
44
45
45
# toy sample
@@ -682,7 +682,8 @@ def test_auto_weight():
682
682
)
683
683
684
684
685
- def test_bad_input ():
685
+ @pytest .mark .parametrize ("lil_container" , LIL_CONTAINERS )
686
+ def test_bad_input (lil_container ):
686
687
# Test dimensions for labels
687
688
Y2 = Y [:- 1 ] # wrong dimensions for labels
688
689
with pytest .raises (ValueError ):
@@ -707,7 +708,7 @@ def test_bad_input():
707
708
# predict with sparse input when trained with dense
708
709
clf = svm .SVC ().fit (X , Y )
709
710
with pytest .raises (ValueError ):
710
- clf .predict (sparse . lil_matrix (X ))
711
+ clf .predict (lil_container (X ))
711
712
712
713
Xt = np .array (X ).T
713
714
clf .fit (np .dot (X , Xt ), Y )
@@ -744,18 +745,18 @@ def test_unicode_kernel():
744
745
)
745
746
746
747
747
- def test_sparse_precomputed ():
748
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
749
+ def test_sparse_precomputed (csr_container ):
748
750
clf = svm .SVC (kernel = "precomputed" )
749
- sparse_gram = sparse . csr_matrix ([[1 , 0 ], [0 , 1 ]])
751
+ sparse_gram = csr_container ([[1 , 0 ], [0 , 1 ]])
750
752
with pytest .raises (TypeError , match = "Sparse precomputed" ):
751
753
clf .fit (sparse_gram , [0 , 1 ])
752
754
753
755
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 ):
755
758
# 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 ]])
759
760
y_train = np .array ([0.04 , 0.04 , 0.10 , 0.16 ])
760
761
model = svm .SVR (kernel = "linear" )
761
762
model .fit (X_train , y_train )
0 commit comments