Exemplo n.º 1
0
# print(heatmap)
# np.savetxt("timepoints_sub5_18reps.csv", heatmap, delimiter=',')

n_comp = 4
csp = CSP(n_components=n_comp, reg=None, log=True, norm_trace=False)
#x, y = data.load_all(cut=[start, end])
#y = np.where(y==1)[1]
#print(x.shape)

print(timepoints)

x, y = data.load_single([5], cut=False)
x = x[0]
y = np.where(y[0] == 1)[1]
for i in range(steps):
    csp.fit_transform(x[:, :, timepoints[i]:timepoints[i] + p_size], y)

    for j in range(n_comp):
        layout = read_layout('EEG1005')
        csp.plot_patterns(info,
                          colorbar=False,
                          layout=layout,
                          ch_type='eeg',
                          size=1.5,
                          show=False,
                          show_names=False,
                          components=j,
                          title="{}".format(int(
                              (timepoints[i] - 768) / 0.512)))
        #plt.savefig('fig/sub9_time_{}_comp_{}.png'.format(i, j))
Exemplo n.º 2
0
    clf = Pipeline([('CSP', csp), ('MLP', mlp)])
    #clf.set_params(CSP__reg=0.5)
    for i in range(100):
        shuffle(labels)
        scores = cross_val_score(clf,
                                 epochs_data_train,
                                 labels,
                                 cv=10,
                                 n_jobs=1)
        accs[sub - 1 if sub < 10 else sub - 2, i] = np.mean(scores)

    # Printing the results
    # print(labels)

    # plot CSP patterns estimated on full data for visualization
    csp.fit_transform(epochs_data, labels)

    layout = read_layout('EEG1005')
    csp.plot_patterns(info,
                      colorbar=True,
                      layout=layout,
                      ch_type='eeg',
                      size=1.5,
                      show=False,
                      show_names=False,
                      scalings=1,
                      title="4 first CSP components")
    plt.savefig('fig/csp_4comp_sub5_cbar.png')

np.savetxt("csp_mlp_scores.csv", accs, delimiter=',')