33
33
assert_array_equal ,
34
34
ignore_warnings ,
35
35
)
36
+ from sklearn .utils .fixes import CSR_CONTAINERS
36
37
37
38
##############################################################################
38
39
# Test the score functions
@@ -63,7 +64,8 @@ def test_f_oneway_ints():
63
64
assert_array_almost_equal (p , pint , decimal = 4 )
64
65
65
66
66
- def test_f_classif ():
67
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
68
+ def test_f_classif (csr_container ):
67
69
# Test whether the F test yields meaningful results
68
70
# on a simple simulated classification problem
69
71
X , y = make_classification (
@@ -81,7 +83,7 @@ def test_f_classif():
81
83
)
82
84
83
85
F , pv = f_classif (X , y )
84
- F_sparse , pv_sparse = f_classif (sparse . csr_matrix (X ), y )
86
+ F_sparse , pv_sparse = f_classif (csr_container (X ), y )
85
87
assert (F > 0 ).all ()
86
88
assert (pv > 0 ).all ()
87
89
assert (pv < 1 ).all ()
@@ -113,7 +115,8 @@ def test_r_regression(center):
113
115
assert_array_almost_equal (np_corr_coeffs , corr_coeffs , decimal = 3 )
114
116
115
117
116
- def test_f_regression ():
118
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
119
+ def test_f_regression (csr_container ):
117
120
# Test whether the F test yields meaningful results
118
121
# on a simple simulated regression problem
119
122
X , y = make_regression (
@@ -129,13 +132,13 @@ def test_f_regression():
129
132
130
133
# with centering, compare with sparse
131
134
F , pv = f_regression (X , y , center = True )
132
- F_sparse , pv_sparse = f_regression (sparse . csr_matrix (X ), y , center = True )
135
+ F_sparse , pv_sparse = f_regression (csr_container (X ), y , center = True )
133
136
assert_allclose (F_sparse , F )
134
137
assert_allclose (pv_sparse , pv )
135
138
136
139
# again without centering, compare with sparse
137
140
F , pv = f_regression (X , y , center = False )
138
- F_sparse , pv_sparse = f_regression (sparse . csr_matrix (X ), y , center = False )
141
+ F_sparse , pv_sparse = f_regression (csr_container (X ), y , center = False )
139
142
assert_allclose (F_sparse , F )
140
143
assert_allclose (pv_sparse , pv )
141
144
@@ -356,7 +359,8 @@ def test_select_percentile_classif():
356
359
assert_array_equal (support , gtruth )
357
360
358
361
359
- def test_select_percentile_classif_sparse ():
362
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
363
+ def test_select_percentile_classif_sparse (csr_container ):
360
364
# Test whether the relative univariate feature selection
361
365
# gets the correct items in a simple classification problem
362
366
# with the percentile heuristic
@@ -373,7 +377,7 @@ def test_select_percentile_classif_sparse():
373
377
shuffle = False ,
374
378
random_state = 0 ,
375
379
)
376
- X = sparse . csr_matrix (X )
380
+ X = csr_container (X )
377
381
univariate_filter = SelectPercentile (f_classif , percentile = 25 )
378
382
X_r = univariate_filter .fit (X , y ).transform (X )
379
383
X_r2 = (
0 commit comments