code: def test_regularized_csp():
      """Test Common Spatial Patterns algorithm using regularized covariance."""
      pytest.importorskip("sklearn")
      raw = io.read_raw_fif(raw_fname)
      events = read_events(event_name)
      picks = pick_types(
          raw.info,
          meg=True,
          stim=False,
          ecg=False,
          eog=False,
          exclude="bads",
      )
      picks = picks[1:13:3]
      epochs = Epochs(
          raw,
          events,
          event_id,
          tmin,
          tmax,
          picks=picks,
          baseline=(None, 0),
          preload=True,
      )
      epochs_data = epochs.get_data(copy=False)
      n_channels = epochs_data.shape[1]
  
      n_components = 3
      reg_cov = [None, 0.05, "ledoit_wolf", "oas"]
      for reg in reg_cov:
          csp = CSP(
              n_components=n_components,
              reg=reg,
              norm_trace=False,
              rank=None,
          )
          csp.fit(epochs_data, epochs.events[:, -1])
          y = epochs.events[:, -1]
          X = csp.fit_transform(epochs_data, y)
          assert csp.filters_.shape == (n_channels, n_channels)
          assert csp.patterns_.shape == (n_channels, n_channels)
          assert_array_almost_equal(
              csp.fit(epochs_data, y).transform(epochs_data), X
          )
  
          # test init exception
          pytest.raises(
              ValueError,
              csp.fit,
              epochs_data,
              np.zeros_like(epochs.events),
          )
          pytest.raises(ValueError, csp.fit, epochs, y)
          pytest.raises(ValueError, csp.transform, epochs)
  
          csp.n_components = n_components
          sources = csp.transform(epochs_data)
          assert sources.shape[1] == n_components
  
file_path: mne-python/mne/decoding/tests/test_csp.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import Epochs, io, pick_types, read_events
  from mne.decoding.csp import CSP, SPoC, _ajd_pham
label_desc: Use image node_id 4 for calling a global function with example usage: test_regularized_csp() without return types