Skip to content

Commit 57bc768

Browse files
authored
TST Extend tests for scipy.sparse.*array in sklearn/decomposition/tests/test_kernel_pca.py (scikit-learn#27143)
1 parent ce41907 commit 57bc768

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sklearn/decomposition/tests/test_kernel_pca.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import numpy as np
44
import pytest
5-
import scipy.sparse as sp
65

76
from sklearn.datasets import make_blobs, make_circles
87
from sklearn.decomposition import PCA, KernelPCA
@@ -17,6 +16,7 @@
1716
assert_array_almost_equal,
1817
assert_array_equal,
1918
)
19+
from sklearn.utils.fixes import CSR_CONTAINERS
2020
from sklearn.utils.validation import _check_psd_eigenvalues
2121

2222

@@ -116,15 +116,16 @@ def test_kernel_pca_deterministic_output():
116116
assert_allclose(transformed_X, np.tile(transformed_X[0, :], 20).reshape(20, 2))
117117

118118

119-
def test_kernel_pca_sparse():
119+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
120+
def test_kernel_pca_sparse(csr_container):
120121
"""Test that kPCA works on a sparse data input.
121122
122123
Same test as ``test_kernel_pca except inverse_transform`` since it's not
123124
implemented for sparse matrices.
124125
"""
125126
rng = np.random.RandomState(0)
126-
X_fit = sp.csr_matrix(rng.random_sample((5, 4)))
127-
X_pred = sp.csr_matrix(rng.random_sample((2, 4)))
127+
X_fit = csr_container(rng.random_sample((5, 4)))
128+
X_pred = csr_container(rng.random_sample((2, 4)))
128129

129130
for eigen_solver in ("auto", "arpack", "randomized"):
130131
for kernel in ("linear", "rbf", "poly"):

0 commit comments

Comments
 (0)