mne-tools / mne-bids-pipeline

Automatically process entire electrophysiological datasets using MNE-Python.
https://mne.tools/mne-bids-pipeline/
BSD 3-Clause "New" or "Revised" License
133 stars 65 forks source link

CSP decoding error: all fits failed #882

Closed SophieHerbst closed 3 months ago

SophieHerbst commented 4 months ago

Sorry, it is me again. I left the preprocessing stage and tried to run the sensor steps. I get an error in csp decoding, pasted below. No changes made in config.

# csp-decoding
decoding_csp = True
decoding_csp_times = np.linspace(0.5, 4, num=16)
decoding_csp_freqs = {'custom_range': np.linspace(2, 30, num=15)}

contrasts = [('1_item', '3_item'),
             ('short', 'long')]

cluster_forming_t_threshold = 0.01
cluster_permutation_p_threshold = 0.01
cluster_n_permutations = 10000
4 fits failed with the following error:
Traceback (most recent call last):
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/model_selection/_validation.py", line 686, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 401, in fit
    Xt = self._fit(X, y, **fit_params_steps)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 359, in _fit
    X, fitted_transformer = fit_transform_one_cached(
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/joblib/memory.py", line 349, in __call__
    return self.func(*args, **kwargs)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 893, in _fit_transform_one
    res = transformer.fit_transform(X, y, **fit_params)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 213, in fit_transform
    return self.fit(epochs_data, y).transform(epochs_data)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 160, in fit
    _sklearn_reshape_apply(self._scaler.fit, False, epochs_data, y=y)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 66, in _sklearn_reshape_apply
    X = func(X, *args, **kwargs)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 40, in fit
    raise ValueError(
ValueError: info had 306 data channels but X has 873983 channels
hoechenberger commented 4 months ago

@larsoner I believe you recently changed something related to PCA / classification in #853, could that be related?

larsoner commented 4 months ago

Yes but I think I also fixed a bug in MNE main can you make sure you're fully up to date?

SophieHerbst commented 4 months ago

I was allready on the developer's version, but even after an upgrade to latest main, I still get the error.

now: ├☑ mne 1.7.0.dev142+ga622a4670 (devel, latest release is 1.6.1) ├☑ mne-bids 0.15.0.dev32+g4fd0ba0 ├☑ mne-bids-pipeline 1.6.0 ├☑ sklearn 1.2.2

before: ├☑ mne 1.7.0.dev126+gae6e55e8e (devel, latest release is 1.6.1) ├☑ mne-bids 0.15.0.dev32+g4fd0ba0 ├☑ mne-bids-pipeline 1.6.0 ├☑ sklearn 1.2.2

hoechenberger commented 4 months ago

It seems as if X is being unraveled / vectorized too early in the decoding pipeline 🤔

hoechenberger commented 4 months ago

@SophieHerbst Is this the complete trackback you're getting? no earlier error messages?

SophieHerbst commented 4 months ago

@hoechenberger here is the complete output:

────────┬ sensor/_05_decoding_csp ───────────────────────────────────────────────────────
│11:10:08│ ⏳️ sub-155 Contrasting conditions: 1_item – 3_item
│11:12:20│ ⏳️ sub-155 Reducing data dimension via PCA; new rank: 70 (from {'meg': 70}).
│11:12:20│ ⏳️ sub-155 Contrast: 1_item – 3_item,  2.0– 4.0 Hz (custom_range)
│11:12:42│ ❌ sub-155 A critical error occurred. The error message was: 
All the 5 fits failed.
It is very likely that your model is misconfigured.
You can try to debug the error by setting error_score='raise'.

Below are more details about the failures:
--------------------------------------------------------------------------------
1 fits failed with the following error:
Traceback (most recent call last):
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/model_selection/_validation.py", line 686, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 401, in fit
    Xt = self._fit(X, y, **fit_params_steps)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 359, in _fit
    X, fitted_transformer = fit_transform_one_cached(
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/joblib/memory.py", line 349, in __call__
    return self.func(*args, **kwargs)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 893, in _fit_transform_one
    res = transformer.fit_transform(X, y, **fit_params)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 213, in fit_transform
    return self.fit(epochs_data, y).transform(epochs_data)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 160, in fit
    _sklearn_reshape_apply(self._scaler.fit, False, epochs_data, y=y)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 66, in _sklearn_reshape_apply
    X = func(X, *args, **kwargs)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 40, in fit
    raise ValueError(
ValueError: info had 306 data channels but X has 870232 channels

--------------------------------------------------------------------------------
4 fits failed with the following error:
Traceback (most recent call last):
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/model_selection/_validation.py", line 686, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 401, in fit
    Xt = self._fit(X, y, **fit_params_steps)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 359, in _fit
    X, fitted_transformer = fit_transform_one_cached(
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/joblib/memory.py", line 349, in __call__
    return self.func(*args, **kwargs)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/pipeline.py", line 893, in _fit_transform_one
    res = transformer.fit_transform(X, y, **fit_params)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 213, in fit_transform
    return self.fit(epochs_data, y).transform(epochs_data)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 160, in fit
    _sklearn_reshape_apply(self._scaler.fit, False, epochs_data, y=y)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 66, in _sklearn_reshape_apply
    X = func(X, *args, **kwargs)
  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne/decoding/transformer.py", line 40, in fit
    raise ValueError(
ValueError: info had 306 data channels but X has 873983 channels

Aborting pipeline run. The traceback is:

  File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/sklearn/model_selection/_validation.py", line 367, in _warn_or_raise_about_fit_failures
    raise ValueError(all_fits_failed_message)
hoechenberger commented 4 months ago

Thanks you, @SophieHerbst

Again I won't be able to really look into this today, but maybe Eric can help! 🙏

hoechenberger commented 4 months ago

@SophieHerbst Last question, do you know the duration and sampling rate of the epochs you're analyzing here?

SophieHerbst commented 4 months ago

The epochs are very long, but we just pick 0.5-4 s in the config decoding_csp_times = np.linspace(0.5, 4, num=16)

Time range  -5.000 – 10.000 s
Baseline    off
Sampling frequency  250.00 Hz
Highpass    0.03 Hz
Lowpass 125.00 Hz
SophieHerbst commented 4 months ago

@larsoner relevant derivatives + config are in shared folder

hoechenberger commented 4 months ago

@larsoner @SophieHerbst Did you manage to make any progress on this one?

SophieHerbst commented 4 months ago

Nope @hoechenberger. I would be greatful for any help to get me unstuck here!