EvokedArray and get_coef - Value Error

Hi,

Using Linear classifier on sensor data with plot patterns and filters β€” MNE 1.6.0 documentation as reference to classify.

X = epochs.pick_types(eeg=True)
y = epochs.events[:, -1]

for name in ('patterns_', 'filters_'):
    # The `inverse_transform` parameter will call this method on any estimator
    # contained in the pipeline, in reverse order.
    coef = get_coef(clf, name, inverse_transform=True)
    evoked = EvokedArray(coef, epochs.info, tmin=epochs.tmin)
    evoked.plot_topomap(title='EEG %s' % name[:-1], time_unit='s')

ValueError: Data must be a 2D array of shape (n_channels, n_samples), got shape (3, 14, 32)

Tried reshaping also. Not able to understand EvokedArray and get_coef.
Can someone help me resolve this error?

  • MNE version: e.g. 0.24.0
  • operating system: Windows 10
    Thanks

hi,

are you just running an example online? are you using your own data?

what is clf in your code?

can you share a full code snippet that runs and replicates the problem?

Alex

Hi @agramfort ,

Using my own data (EEG channels + label). Have used vectorizer between mne and scikit-learn also.

Using the same clf first.

clf = make_pipeline(
    Vectorizer(),                       # 1) vectorize across time and channels
    StandardScaler(),                   # 2) normalize features across trials
    LinearModel(                        # 3) fits a logistic regression
        LogisticRegression(solver='liblinear')
    )
)
clf.fit(X, y)

Let me know if you need more details.
Can you please help me resolve this error?

Thanks Alex

This is important for us to be able to help you. If you don’t do this, it means we have to

  1. use different data than you
  2. write our own code to load the data
  3. write our own code to preprocess the raw data into Epochs
  4. figure out what packages your various functions come from (since your code doesn’t include any import statements)

It is impossible for us to do that for every question on this forum, there is simply not enough time. Please try to write a minimal working example that includes all necessary imports, data loading, etc. Try to reproduce your error with the MNE sample data or some other built-in dataset. If you cannot replicate with a built-in dataset, then provide a link where we can download the data that does cause the error. Finally, when you get an error, please copy/paste the full traceback printed in the console, not just the final error message. Sometimes seeing that helps us a lot to pinpoint where the problem is coming from.

1 Like