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