[Mne_analysis] Linear classifier on sensor data with plot patterns and filters

Пилюгина Нина aphina_n at outlook.com
Wed Feb 6 04:10:19 EST 2019
Search archives:

        External Email - Use Caution        

Well, I didn't change code much, only add my data.
I'm really confused where I made a mistake.

Now it looks this way:

data_path = 'C:/Users/Public/MEG/asami_ryo/170809/Asami1_raw.fif'


#print(raw_data)
#print(raw_data.ch_names[:204])
tmin, tmax = 0, 10.26
event_id = dict(l=1, r=2, n=4)

raw_data = mne.io.read_raw_fif(data_path, preload=True)
raw_data.filter(1.0, None, fir_design='firwin')
#raw_data.crop(tmin, tmax).load_data()
events = mne.find_events (raw_data)
picks = mne.pick_types(raw_data.info, meg=True, eeg=True, stim=False, eog=False)
epochs = mne.Epochs(raw_data, events, event_id=event_id, tmin=tmin, tmax=tmax, proj=False,baseline=(None, 0), preload=True,verbose=False)
labels = epochs.events[:, -1]

# get MEG and EEG data
meg_epochs = epochs.copy().pick_types(meg=True, eeg=False)
meg_data = meg_epochs.get_data().reshape(len(labels), -1)

clf = LogisticRegression(solver='lbfgs')
scaler = StandardScaler()

# create a linear model with LogisticRegression
model = LinearModel(clf)

# fit the classifier on MEG data
X = scaler.fit_transform(meg_data)
model.fit(X, labels)

# Extract and plot spatial filters and spatial patterns
for name, coef in (('patterns', model.patterns_), ('filters', model.filters_)):
    # We fitted the linear model onto Z-scored data. To make the filters
    # interpretable, we must reverse this normalization step
    coef = scaler.inverse_transform([coef])[0]

    # The data was vectorized to fit a single model across all time points and
    # all channels. We thus reshape it:
    coef = coef.reshape(len(meg_epochs.ch_names), -1)

    # Plot
    evoked = EvokedArray(coef, meg_epochs.info, tmin=epochs.tmin)
    evoked.plot_topomap(title='MEG %s' % name, time_unit='s')
________________________________
От: mne_analysis-bounces at nmr.mgh.harvard.edu <mne_analysis-bounces at nmr.mgh.harvard.edu> от имени Alexandre Gramfort <alexandre.gramfort at inria.fr>
Отправлено: 6 февраля 2019 г. 15:56
Кому: Discussion and support forum for the users of MNE Software
Тема: Re: [Mne_analysis] Linear classifier on sensor data with plot patterns and filters

        External Email - Use Caution

hi,

I don't think your error is related to MNE.

I suspect you want to compute cov(X.T) and not cov(X) ie
you swapped rows and columns

HTH
Alex

On Wed, Feb 6, 2019 at 7:13 AM Пилюгина Нина <Aphina_N at outlook.com> wrote:
>
>         External Email - Use Caution
>
> Hello
>
> I was thing to do this example with my data, but in the end, I only get this error:
>   File "C:\Anaconda3\envs\mne\lib\site-packages\numpy\lib\function_base.py", line 2325, in cov
>     c = dot(X, X_T.conj())
>
> MemoryError
>
> What can cause it?
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis

_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190206/5b33c6b8/attachment-0001.html 


More information about the Mne_analysis mailing list