本文整理汇总了Python中mne.decoding.GeneralizationAcrossTime.plot方法的典型用法代码示例。如果您正苦于以下问题:Python GeneralizationAcrossTime.plot方法的具体用法?Python GeneralizationAcrossTime.plot怎么用?Python GeneralizationAcrossTime.plot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.decoding.GeneralizationAcrossTime
的用法示例。
在下文中一共展示了GeneralizationAcrossTime.plot方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_pipeline
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
epochs_data.equalize_event_counts(["0", "1"])
# Classifier
clf = make_pipeline(StandardScaler(), LogisticRegression(C=1))
# Setup the y vector and GAT
gat = GeneralizationAcrossTime(
predict_mode='mean-prediction', scorer="roc_auc", n_jobs=1)
# Fit model
print("fitting GAT")
gat.fit(epochs_data)
# Scoring
print("Scoring GAT")
gat.score(epochs_data)
# Save model
joblib.dump(
gat, data_path + "decode_time_gen/%s_gat_allsensor-grad_ctl.jl" % subject)
# make matrix plot and save it
fig = gat.plot(cmap="viridis", title="Temporal Gen for subject: %s" % subject)
fig.savefig(data_path + "decode_time_gen/%s_gat_matrix_allsensor-grad_ctl.png"
% subject)
fig = gat.plot_diagonal(
chance=0.5, title="Temporal Gen for subject: %s" % subject)
fig.savefig(data_path +
"decode_time_gen/%s_gat_diagonal_allsensor-grad_ctl.png" % subject)
示例2: GeneralizationAcrossTime
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
epochs = mne.Epochs(raw, events, event_id, -0.050, 0.400, proj=True,
picks=picks, baseline=None, preload=True,
reject=dict(mag=5e-12), decim=decim, verbose=False)
# We will train the classifier on all left visual vs auditory trials
# and test on all right visual vs auditory trials.
# In this case, because the test data is independent from the train data,
# we test the classifier of each fold and average the respective predictions.
# Define events of interest
triggers = epochs.events[:, 2]
viz_vs_auditory = np.in1d(triggers, (1, 2)).astype(int)
gat = GeneralizationAcrossTime(predict_mode='mean-prediction', n_jobs=1)
# For our left events, which ones are visual?
viz_vs_auditory_l = (triggers[np.in1d(triggers, (1, 3))] == 3).astype(int)
# To make scikit-learn happy, we converted the bool array to integers
# in the same line. This results in an array of zeros and ones:
print("The unique classes' labels are: %s" % np.unique(viz_vs_auditory_l))
gat.fit(epochs[('AudL', 'VisL')], y=viz_vs_auditory_l)
# For our right events, which ones are visual?
viz_vs_auditory_r = (triggers[np.in1d(triggers, (2, 4))] == 4).astype(int)
gat.score(epochs[('AudR', 'VisR')], y=viz_vs_auditory_r)
gat.plot(
title="Generalization Across Time (visual vs auditory): left to right")
示例3: StratifiedKFold
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
# Here we'll use a stratified cross-validation scheme.
# make response vector
y = np.zeros(len(epochs.events), dtype=int)
y[epochs.events[:, 2] == 3] = 1
cv = StratifiedKFold(y=y) # do a stratified cross-validation
# define the GeneralizationAcrossTime object
gat = GeneralizationAcrossTime(predict_mode="cross-validation", n_jobs=1, cv=cv, scorer=roc_auc_score)
# fit and score
gat.fit(epochs, y=y)
gat.score(epochs)
# let's visualize now
gat.plot()
gat.plot_diagonal()
###############################################################################
# Exercise
# --------
# - Can you improve the performance using full epochs and a common spatial
# pattern (CSP) used by most BCI systems?
# - Explore other datasets from MNE (e.g. Face dataset from SPM to predict
# Face vs. Scrambled)
#
# Have a look at the example
# :ref:`sphx_glr_auto_examples_decoding_plot_decoding_csp_space.py`
#
# References
# ==========
示例4: make_pipeline
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
clf = make_pipeline(StandardScaler(), clf)
# initialize the GAT object
gat = GeneralizationAcrossTime(clf=clf, scorer=scorer_auc, n_jobs=-1,
cv=10)
# select the trials where a target is presented
for contrast in ['HL', 'EU', 'PR']:
epochs_ = concatenate_epochs((epochs[contrast[0]],
epochs[contrast[1]]))
y = np.hstack((np.zeros(len(epochs[contrast[0]])),
np.ones(len(epochs[contrast[1]]))))
gat.fit(epochs_, y=y)
fname = op.join(data_path, 's%i_%s_fit.pkl' % (subject, contrast))
with open(fname, 'wb') as f:
pickle.dump(gat, f)
# TODO: should save y_pred separately
# predict + score
scores = gat.score(epochs_, y=y)
fname = op.join(data_path,
's%i_%s_scores.npy' % (subject, contrast))
np.save(fname, np.array(scores))
all_scores[contrast].append(np.array(scores))
# plot
fig, axes = plt.subplots(2, 1, facecolor='w')
gat.plot_diagonal(show=False, ax=axes[0], chance=.5)
gat.plot(show=False, ax=axes[1], vmin=.25, vmax=.75)
report.add_figs_to_section(fig, str(subject), contrast)
report.save()
示例5: GeneralizationAcrossTime
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
# Apply contrast
if clf_type['name']=='SVC':
decoding_parameters = decoding_params[0]['values']
elif clf_type['name']=='SVR':
decoding_parameters = decoding_params[1]['values']
gat = GeneralizationAcrossTime(**decoding_parameters)
gat.fit(epochs[sel], y=y[sel])
gat.score(epochs[sel], y=y[sel])
# Plot
fig = gat.plot_diagonal(show=False)
report.add_figs_to_section(fig,
('%s %s: (decoding)' % (subject, cond_name)), subject)
fig = gat.plot(show=False)
report.add_figs_to_section(fig,
('%s %s: GAT' % (subject, cond_name)), subject)
# Save contrast
pkl_fname = op.join(data_path, subject, 'mvpas',
'{}-decod_{}_{}{}.pickle'.format(subject, cond_name,clf_type['name'],fname_appendix))
# Save classifier results
with open(pkl_fname, 'wb') as f:
pickle.dump([gat, contrast], f)
break
break
break
示例6: GeneralizationAcrossTime
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
decim = 2 # decimate to make the example faster to run
epochs = mne.Epochs(raw, events, event_id, -0.050, 0.400, proj=True,
picks=picks, baseline=None, preload=True,
reject=dict(mag=5e-12), decim=decim, verbose=False)
# We will train the classifier on all left visual vs auditory trials
# and test on all right visual vs auditory trials.
# In this case, because the test data is independent from the train data,
# we test the classifier of each fold and average the respective predictions.
# Define events of interest
triggers = epochs.events[:, 2]
viz_vs_auditory = np.in1d(triggers, (1, 2)).astype(int)
gat = GeneralizationAcrossTime(predict_mode='mean-prediction', n_jobs=1)
# For our left events, which ones are visual?
viz_vs_auditory_l = (triggers[np.in1d(triggers, (1, 3))] == 3).astype(int)
# To make scikit-learn happy, we converted the bool array to integers
# in the same line. This results in an array of zeros and ones:
print("The unique classes' labels are: %s" % np.unique(viz_vs_auditory_l))
gat.fit(epochs[('AudL', 'VisL')], y=viz_vs_auditory_l)
# For our right events, which ones are visual?
viz_vs_auditory_r = (triggers[np.in1d(triggers, (2, 4))] == 4).astype(int)
gat.score(epochs[('AudR', 'VisR')], y=viz_vs_auditory_r)
gat.plot(title="Temporal Generalization (visual vs auditory): left to right")
开发者ID:deep-introspection,项目名称:mne-python,代码行数:32,代码来源:plot_decoding_time_generalization_conditions.py
示例7: LogisticRegression
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
epochs.times = selected_times[:n_time]
# make classifier
clf = LogisticRegression(C=0.0001)
# fit model and score
gat = GeneralizationAcrossTime(
clf=clf, scorer="roc_auc", cv=cv, predict_method="predict")
gat.fit(epochs, y=y)
gat.score(epochs, y=y)
# Save model
joblib.dump(gat, data_path + "decode_time_gen/gat_ge.jl")
# make matrix plot and save it
fig = gat.plot(
cmap="viridis", title="Temporal Gen (Classic vs planning) for Global Eff.")
fig.savefig(data_path + "decode_time_gen/gat_matrix_ge.png")
fig = gat.plot_diagonal(
chance=0.5, title="Temporal Gen (Classic vs planning) for Global eff.")
fig.savefig(data_path + "decode_time_gen/gat_diagonal_ge.png")
# Manuel model
X2 = np.vstack([data_cls.reshape((13, -1)), data_pln.reshape(13, -1)])
ada = AdaBoostClassifier()
adaboost_params = {
"n_estimators": np.arange(1, 21, 1),
"learning_rate": np.arange(0.1, 1.1, 0.1)
}
示例8: GeneralizationAcrossTime
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
mne.equalize_channels([epochs_classic, epochs_plan])
mne.epochs.equalize_epoch_counts([epochs_classic, epochs_plan])
# Dirty hack # TODO: Check this from the Maxfilter side
# epochs_classic.info['dev_head_t'] = epochs_plan.info['dev_head_t']
epochs = mne.concatenate_epochs([epochs_classic, epochs_plan])
# Crop and downsmample to make it faster
epochs.crop(tmin=-3.5, tmax=0)
epochs.resample(250)
# Setup the y vector and GAT
y = np.concatenate(
(np.zeros(len(epochs["press"])), np.ones(len(epochs["plan"]))))
gat = GeneralizationAcrossTime(
predict_mode='mean-prediction', scorer="roc_auc", n_jobs=1)
# Fit model
# Scoring and visualise result
gat.score(epochs, y=y)
# Save model
joblib.dump(gat, data_path + "decode_time_gen/%s_gat_2.jl" % subject)
fig = gat.plot(
title="Temporal Gen (Classic vs planning): left to right sub: %s" %
subject)
fig.savefig(data_path + "decode_time_gen/%s_gat_matrix_2.png" % subject)
示例9: range
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
n_trial, n_chan, n_time = X.shape
events = np.vstack((range(n_trial), np.zeros(n_trial, int), y.astype(int))).T
chan_names = ['MEG %i' % chan for chan in range(n_chan)]
chan_types = ['mag'] * n_chan
sfreq = 250
info = create_info(chan_names, sfreq, chan_types)
epochs = EpochsArray(data=X, info=info, events=events, verbose=False)
epochs.times = selected_times[:n_time]
# make classifier
clf = LogisticRegression(C=0.0001)
# fit model and score
gat = GeneralizationAcrossTime(
clf=clf, scorer="roc_auc", cv=cv, predict_method="predict")
gat.fit(epochs, y=y)
gat.score(epochs, y=y)
# Save model
joblib.dump(gat, data_path + "decode_time_gen/gat_cp.jl")
# make matrix plot and save it
fig = gat.plot(
cmap="viridis", title="Temporal Gen (Classic vs planning) for CharPath")
fig.savefig(data_path + "decode_time_gen/%s_gat_matrix_cp.png")
fig = gat.plot_diagonal(
chance=0.5, title="Temporal Gen (Classic vs planning) for CharPath")
fig.savefig(data_path + "decode_time_gen/gat_diagonal_cp.png")
示例10: GeneralizationAcrossTime
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
# Apply analysis
gat = GeneralizationAcrossTime(clf=analysis['clf'],
cv=analysis['cv'],
scorer=analysis['scorer'],
n_jobs=-1)
gat.fit(epochs[sel], y=y[sel])
gat.score(epochs[sel], y=y[sel])
# Save analysis
pkl_fname = paths('decod', subject=subject, data_type=data_type,
analysis=analysis['name'], log=True)
# Save classifier results
with open(pkl_fname, 'wb') as f:
pickle.dump([gat, analysis, sel, events], f)
# Plot
fig = gat.plot_diagonal(show=False)
report.add_figs_to_section(fig, ('%s %s %s: (diagonal)' %
(subject, data_type, analysis['name'])),
analysis['name'])
fig = gat.plot(vmin=np.min(gat.scores_),
vmax=np.max(gat.scores_), show=False)
report.add_figs_to_section(fig, ('%s %s %s: GAT' % (
subject, data_type, analysis['name'])),
analysis['name'])
report.save(open_browser=open_browser)
upload_report(report)
示例11: print
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
print(__doc__)
# Preprocess data
data_path = spm_face.data_path()
# Load and filter data, set up epochs
raw_fname = data_path + '/MEG/spm/SPM_CTF_MEG_example_faces%d_3D_raw.fif'
raw = mne.io.Raw(raw_fname % 1, preload=True) # Take first run
picks = mne.pick_types(raw.info, meg=True, exclude='bads')
raw.filter(1, 45, method='iir')
events = mne.find_events(raw, stim_channel='UPPT001')
event_id = {"faces": 1, "scrambled": 2}
tmin, tmax = -0.1, 0.5
decim = 4 # decimate to make the example faster to run
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=picks, baseline=None, preload=True,
reject=dict(mag=1.5e-12), decim=decim, verbose=False)
# Define decoder. The decision function is employed to use cross-validation
gat = GeneralizationAcrossTime(predict_mode='cross-validation', n_jobs=1)
# fit and score
gat.fit(epochs)
gat.score(epochs)
gat.plot(vmin=0.1, vmax=0.9,
title="Generalization Across Time (faces vs. scrambled)")
gat.plot_diagonal() # plot decoding across time (correspond to GAT diagonal)
示例12: range
# 需要导入模块: from mne.decoding import GeneralizationAcrossTime [as 别名]
# 或者: from mne.decoding.GeneralizationAcrossTime import plot [as 别名]
# Create epochs to use for classification
n_trial, n_chan, n_time = X.shape
events = np.vstack((range(n_trial), np.zeros(n_trial, int), y.astype(int))).T
chan_names = ['MEG %i' % chan for chan in range(n_chan)]
chan_types = ['mag'] * n_chan
sfreq = 250
info = create_info(chan_names, sfreq, chan_types)
epochs = EpochsArray(data=X, info=info, events=events, verbose=False)
epochs.times = selected_times[:n_time]
epochs.crop(-3.8, None)
# fit model and score
gat = GeneralizationAcrossTime(
scorer="accuracy", cv=cv, predict_method="predict")
gat.fit(epochs, y=y)
gat.score(epochs, y=y)
# Save model
joblib.dump(gat, data_path + "decode_time_gen/%s_gat_tr.jl" % subject)
# make matrix plot and save it
fig = gat.plot(
cmap="viridis",
title="Temporal Gen (Classic vs planning) for transitivity.")
fig.savefig(data_path + "decode_time_gen/%s_gat_matrix_tr.png" % subject)
fig = gat.plot_diagonal(
chance=0.5, title="Temporal Gen (Classic vs planning) for transitivity")
fig.savefig(data_path + "decode_time_gen/%s_gat_diagonal_tr.png" % subject)