code: def test_xdawn_regularization():
      """Test Xdawn with regularization."""
      pytest.importorskip("sklearn")
      # Get data, this time MEG so we can test proper reg/ch type support
      raw = read_raw_fif(raw_fname, verbose=False, preload=True)
      events = read_events(event_name)
      picks = pick_types(
          raw.info,
          meg=True,
          eeg=False,
          stim=False,
          ecg=False,
          eog=False,
          exclude="bads",
      )[::8]
      raw.pick([raw.ch_names[pick] for pick in picks])
      del picks
      raw.info.normalize_proj()
      epochs = Epochs(
          raw,
          events,
          event_id,
          tmin,
          tmax,
          preload=True,
          baseline=None,
          verbose=False,
      )
  
      # Test with overlapping events.
      # modify events to simulate one overlap
      events = epochs.events
      sel = np.where(events[:, 2] == 2)[0][:2]
      modified_event = events[sel[0]]
      modified_event[0] += 1
      epochs.events[sel[1]] = modified_event
      # Fit and check that overlap was found and applied
      xd = Xdawn(n_components=2, correct_overlap="auto", reg="oas")
      xd.fit(epochs)
      assert xd.correct_overlap_
      evoked = epochs["cond2"].average()
      assert np.sum(np.abs(evoked.data - xd.evokeds_["cond2"].data))
  
      # With covariance regularization
      for reg in [0.1, 0.1, "ledoit_wolf", "oas"]:
          xd = Xdawn(
              n_components=2,
              correct_overlap=False,
              signal_cov=np.eye(len(epochs.ch_names)),
              reg=reg,
          )
          xd.fit(epochs)
      # With bad shrinkage
      xd = Xdawn(
          n_components=2,
          correct_overlap=False,
          signal_cov=np.eye(len(epochs.ch_names)),
          reg=2,
      )
      with pytest.raises(ValueError, match="shrinkage must be"):
          xd.fit(epochs)
      # With rank-deficient input
      # this is a bit wacky because `epochs` has projectors on from the old raw
      # but it works as a rank-deficient test case
      xd = Xdawn(correct_overlap=False, reg=0.5)
      xd.fit(epochs)
      xd = Xdawn(correct_overlap=False, reg="diagonal_fixed")
      xd.fit(epochs)
  
file_path: mne-python/mne/preprocessing/tests/test_xdawn.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal
  from scipy import stats
  from mne import Epochs, EpochsArray, compute_raw_covariance, create_info, pick_types, read_events
  from mne.decoding import Vectorizer
  from mne.fixes import _safe_svd
  from mne.io import read_raw_fif
  from mne.preprocessing.xdawn import Xdawn, _XdawnTransformer
label_desc: Use image node_id 6 for calling a global function with example usage: test_xdawn_regularization() without return types