Linear classifier on sensor data with plot patterns and filters

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190206/71c6c057/attachment.html

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

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')

External Email - Use Caution

what is the size of meg_data for you? how does it compare with what is
used in mne example?

Alex

External Email - Use Caution

??? ??? ??? ??? ??? ??? ? ??? OneDrive. ??? ??? ???, ??? ??? ???.

<https://1drv.ms/u/s!AsTbwfRXq04Aa0PWbR2gdb0UdLU>
[https://r1.res.office365.com/owa/prem/images/dc-generic_20.png]<https://1drv.ms/u/s!AsTbwfRXq04Aa0PWbR2gdb0UdLU>

Asami1_raw.fif<https://1drv.ms/u/s!AsTbwfRXq04Aa0PWbR2gdb0UdLU>

I didn' checked the sample data of this example, just add mine raw data. It's one session with one person, so I assumed I can't it worse.

External Email - Use Caution

please check first with sample data. If you have a pb with sample you have
a setup / hardware limitation.

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190206/effbe745/attachment-0001.html

External Email - Use Caution

Tried, but it works well with a sample data.

So it's be because I'm using a to big raw file? I need crop it? Or it's because of different filter's settings?

External Email - Use Caution

I cannot guess.

I need to know the size of the new data.

Alex

External Email - Use Caution

I think it s because you reshape your meg data (n_trials, n_sensors,
n_times) into a matrix (n_trials, n_sensors * n_times)

meg_data = meg_epochs.get_data().reshape(len(labels), -1)

The covariance of this matrix will be pretty heavy.

JR

External Email - Use Caution

It's 278 mb heavy, around 6 minutes.

External Email - Use Caution

I did reshape because it's in example, if it's too heavy I should refuse this conversion?

External Email - Use Caution

what is n_times for you?
basically how many samples and features do you have?

A

External Email - Use Caution

n_times is 348000 and total projection items are 10.

Probably there's a very simple solution, but I'm quite new for all this.

External Email - Use Caution

learning in dimension 348000 with 10 samples is not realistic.
You need more sample and to reduce the feature space / dimension.

Alex