MCPcopy
hub / github.com/mne-tools/mne-python / test_vectorizer

Function test_vectorizer

mne/decoding/tests/test_transformer.py:206–233  ·  view source on GitHub ↗

Test Vectorizer.

()

Source from the content-addressed store, hash-verified

204
205
206def 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
236def test_unsupervised_spatial_filter():

Callers

nothing calls this directly

Calls 8

fit_transformMethod · 0.95
inverse_transformMethod · 0.95
fitMethod · 0.95
VectorizerClass · 0.90
EpochsArrayClass · 0.90
create_infoFunction · 0.90
LinearModelClass · 0.90
fitMethod · 0.45

Tested by

no test coverage detected