8000 TST add sparse containers · scikit-learn/scikit-learn@ea05f4c · GitHub
[go: up one dir, main page]

Skip to content

Commit ea05f4c

Browse files
committed
TST add sparse containers
1 parent a823012 commit ea05f4c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

sklearn/feature_selection/tests/test_feature_select.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
assert_array_equal,
3434
ignore_warnings,
3535
)
36+
from sklearn.utils.fixes import CSR_CONTAINERS
3637

3738
##############################################################################
3839
# Test the score functions
@@ -63,7 +64,8 @@ def test_f_oneway_ints():
6364
assert_array_almost_equal(p, pint, decimal=4)
6465

6566

66-
def test_f_classif():
67+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
68+
def test_f_classif(csr_container):
6769
# Test whether the F test yields meaningful results
6870
# on a simple simulated classification problem
6971
X, y = make_classification(
@@ -81,7 +83,7 @@ def test_f_classif():
8183
)
8284

8385
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)
8587
assert (F > 0).all()
8688
assert (pv > 0).all()
8789
assert (pv < 1).all()
@@ -113,7 +115,8 @@ def test_r_regression(center):
113115
assert_array_almost_equal(np_corr_coeffs, corr_coeffs, decimal=3)
114116

115117

116-
def test_f_regression():
118+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
119+
def test_f_regression(csr_container):
117120
# Test whether the F test yields meaningful results
118121
# on a simple simulated regression problem
119122
X, y = make_regression(
@@ -129,13 +132,13 @@ def test_f_regression():
129132

130133
# with centering, compare with sparse
131134
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)
133136
assert_allclose(F_sparse, F)
134137
assert_allclose(pv_sparse, pv)
135138

136139
# again without centering, compare with sparse
137140
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)
139142
assert_allclose(F_sparse, F)
140143
assert_allclose(pv_sparse, pv)
141144

@@ -356,7 +359,8 @@ def test_select_percentile_classif():
356359
assert_array_equal(support, gtruth)
357360

358361

359-
def test_select_percentile_classif_sparse():
362+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
363+
def test_select_percentile_classif_sparse(csr_container):
360364
# Test whether the relative univariate feature selection
361365
# gets the correct items in a simple classification problem
362366
# with the percentile heuristic
@@ -373,7 +377,7 @@ def test_select_percentile_classif_sparse():
373377
shuffle=False,
374378
random_state=0,
375379
)
376-
X = sparse.csr_matrix(X)
380+
X = csr_container(X)
377381
univariate_filter = SelectPercentile(f_classif, percentile=25)
378382
X_r = univariate_filter.fit(X, y).transform(X)
379383
X_r2 = (

0 commit comments

Comments
 (0)
0