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()
fig_diag, axes_diag = plt.subplots(len(contrasts), 1, figsize=[2, 5]) cmap = plt.get_cmap('rainbow') colors = cmap(np.linspace(0., 1., len(contrasts))) for contrast, color, ax in zip(contrasts, colors, axes_diag): scores = all_scores[contrast] # plot diagonal scores_diag = np.array([np.diag(x) for x in scores]) pretty_decod(scores_diag, times=times, color=color, ax=ax, chance=.5) ax.set_title(contrast) if ax != axes_diag[-1]: ax.set_xticklabels([]) ax.set_xlabel('') # plot gat fig, ax = plt.subplots(1, figsize=[5, 5]) pretty_gat(np.mean(scores, axis=0), times=times, chance=.5) report.add_figs_to_section(fig, 'GAT %s' % contrast, contrast) # plot slices tois = np.arange(0., .600, .100) fig, axes = plt.subplots(len(tois), 1, figsize=[5, 5]) pretty_slices(scores, tois=tois, times=times, chance=.5, axes=axes) report.add_figs_to_section(fig, 'Slices %s' % contrast, contrast) fig_diag.tight_layout() report.add_figs_to_section(fig_diag, 'Diagonal', 'All') # plot subscore for contrast in ['EU', 'PR']: fig_diag, ax_diag = plt.subplots(1, figsize=[5, 2]) for HL in 'HL': subcontrast = '%s_%s' % (contrast, HL) scores = all_scores[subcontrast] # plot diagonal