Test Vectorizer.
()
| 204 | |
| 205 | |
| 206 | def test_vectorizer(): |
| 207 | """Test Vectorizer.""" |
| 208 | data = np.random.rand(150, 18, 6) |
| 209 | vect = Vectorizer() |
| 210 | result = vect.fit_transform(data) |
| 211 | assert_equal(result.ndim, 2) |
| 212 | |
| 213 | # check inverse_trasnform |
| 214 | orig_data = vect.inverse_transform(result) |
| 215 | assert_equal(orig_data.ndim, 3) |
| 216 | assert_array_equal(orig_data, data) |
| 217 | assert_array_equal(vect.inverse_transform(result[1:]), data[1:]) |
| 218 | |
| 219 | # check with different shape |
| 220 | assert_equal(vect.fit_transform(np.random.rand(150, 18, 6, 3)).shape, (150, 324)) |
| 221 | assert_equal(vect.fit_transform(data[1:]).shape, (149, 108)) |
| 222 | |
| 223 | # check if raised errors are working correctly |
| 224 | X = np.random.default_rng(0).standard_normal((105, 12, 3)) |
| 225 | y = np.arange(X.shape[0]) % 2 |
| 226 | pytest.raises(ValueError, vect.transform, X[..., np.newaxis]) |
| 227 | pytest.raises(ValueError, vect.inverse_transform, X[:, :-1]) |
| 228 | |
| 229 | # And that pipelines work properly |
| 230 | X_arr = EpochsArray(X, create_info(12, 1000.0, "eeg")) |
| 231 | vect.fit(X_arr) |
| 232 | clf = make_pipeline(Vectorizer(), StandardScaler(), LinearModel()) |
| 233 | clf.fit(X_arr, y) |
| 234 | |
| 235 | |
| 236 | def test_unsupervised_spatial_filter(): |
nothing calls this directly
no test coverage detected