|
2 | 2 |
|
3 | 3 | import numpy as np
|
4 | 4 | import pytest
|
5 |
| -import scipy.sparse as sp |
6 | 5 |
|
7 | 6 | from sklearn.datasets import make_blobs, make_circles
|
8 | 7 | from sklearn.decomposition import PCA, KernelPCA
|
|
17 | 16 | assert_array_almost_equal,
|
18 | 17 | assert_array_equal,
|
19 | 18 | )
|
| 19 | +from sklearn.utils.fixes import CSR_CONTAINERS |
20 | 20 | from sklearn.utils.validation import _check_psd_eigenvalues
|
21 | 21 |
|
22 | 22 |
|
@@ -116,15 +116,16 @@ def test_kernel_pca_deterministic_output():
|
116 | 116 | assert_allclose(transformed_X, np.tile(transformed_X[0, :], 20).reshape(20, 2))
|
117 | 117 |
|
118 | 118 |
|
119 |
| -def test_kernel_pca_sparse(): |
| 119 | +@pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 120 | +def test_kernel_pca_sparse(csr_container): |
120 | 121 | """Test that kPCA works on a sparse data input.
|
121 | 122 |
|
122 | 123 | Same test as ``test_kernel_pca except inverse_transform`` since it's not
|
123 | 124 | implemented for sparse matrices.
|
124 | 125 | """
|
125 | 126 | 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))) |
128 | 129 |
|
129 | 130 | for eigen_solver in ("auto", "arpack", "randomized"):
|
130 | 131 | for kernel in ("linear", "rbf", "poly"):
|
|
0 commit comments