11
11
12
12
import numpy as np
13
13
import pytest
14
- import scipy .sparse as sp
15
14
from scipy .stats import bernoulli , expon , uniform
16
15
17
16
from sklearn .base import BaseEstimator , ClassifierMixin , is_classifier
77
76
assert_array_equal ,
78
77
ignore_warnings ,
79
78
)
79
+ from sklearn .utils .fixes import CSR_CONTAINERS
80
80
from sklearn .utils .validation import _num_samples
81
81
82
82
@@ -489,7 +489,8 @@ def test_grid_search_bad_param_grid():
489
489
search .fit (X , y )
490
490
491
491
492
- def test_grid_search_sparse ():
492
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
493
+ def test_grid_search_sparse (csr_container ):
493
494
# Test that grid search works with both dense and sparse matrices
494
495
X_ , y_ = make_classification (n_samples = 200 , n_features = 100 , random_state = 0 )
495
496
@@ -499,7 +500,7 @@ def test_grid_search_sparse():
499
500
y_pred = cv .predict (X_ [180 :])
500
501
C = cv .best_estimator_ .C
501
502
502
- X_ = sp . csr_matrix (X_ )
503
+ X_ = csr_container (X_ )
503
504
clf = LinearSVC (dual = "auto" )
504
505
cv = GridSearchCV (clf , {"C" : [0.1 , 1.0 ]})
505
506
cv .fit (X_ [:180 ].tocoo (), y_ [:180 ])
@@ -510,7 +511,8 @@ def test_grid_search_sparse():
510
511
assert C == C2
511
512
512
513
513
- def test_grid_search_sparse_scoring ():
514
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
515
+ def test_grid_search_sparse_scoring (csr_container ):
514
516
X_ , y_ = make_classification (n_samples = 200 , n_features = 100 , random_state = 0 )
515
517
516
518
clf = LinearSVC (dual = "auto" )
@@ -519,7 +521,7 @@ def test_grid_search_sparse_scoring():
519
521
y_pred = cv .predict (X_ [180 :])
520
522
C = cv .best_estimator_ .C
521
523
522
- X_ = sp . csr_matrix (X_ )
524
+ X_ = csr_container (X_ )
523
525
clf = LinearSVC (dual = "auto" )
524
526
cv = GridSearchCV (clf , {"C" : [0.1 , 1.0 ]}, scoring = "f1" )
525
527
cv .fit (X_ [:180 ], y_ [:180 ])
0 commit comments