y_train = y_true[train_index]
        # transform
        X_test = xdawn.transform(epochs[test_index])
        y_test = y_true[test_index]

        # All time decoder
        # Fit
        raw_decoder.fit(X_train, y_train)
        # Predict
        y_pred[test_index] = raw_decoder.predict(X_test)

        # Time decoder
        # Fit
        time_decoder.fit(X_train, y_train)
        # Predict
        y_pred_time[test_index] = time_decoder.predict(X_test)

        # Time window decoder
        for window_length, _info in time_windows.items():
            # _info[0], w_start
            # _info[1], w_length
            # _info[2], w_time
            w_length = _info[1]
            for j, w_start in enumerate(_info[0]):
                w_stop = w_start + w_length
                print(w_start)
                # Crop X_train and X_test
                _X_train = X_train[:, :, w_start:w_start + w_length]
                _X_test = X_test[:, :, w_start:w_start + w_length]
                # Fit
                raw_decoder.fit(_X_train, y_train)
Ejemplo n.º 2
0
y_all = np.concatenate([y1, y2], axis=0)
X_all.shape, y_all.shape

times = worker.clean_epochs.times

n_splits = int(y1.shape[0] / 64)

y_pred_time = np.zeros((3313, 141))

skf = StratifiedKFold(n_splits=n_splits, shuffle=False)
for train_index, test_index in skf.split(X_all, y_all):
    X_train, y_train = X_all[train_index], y_all[train_index]
    X_test, y_test = X_all[test_index], y_all[test_index]

    estimator.fit(X_train, y_train)
    y_pred_time[test_index] = estimator.predict(X_test)

# %%
y_pred_time.shape

# %%
report = metrics.classification_report(y_true=y_all,
                                       y_pred=y_pred_time[:, 60],
                                       output_dict=True)
print(report)

# %%


def fuck_report(report):
    # I don't know why report has to be 2-layers dictionary,
Ejemplo n.º 3
0
    # Prepare predicted label matrix
    num_samples, num_times = X_all.shape[0], X_all.shape[2]
    y_pred_sliding = np.zeros((num_samples, num_times))

    # Cross validation
    skf = StratifiedKFold(n_splits=n_splits, shuffle=False)
    for train_index, test_index in skf.split(X_all, y_all):
        # Separate training and testing data
        X_train, y_train = X_all[train_index], y_all[train_index]
        X_test, y_test = X_all[test_index], y_all[test_index]

        # Fit estimator
        estimator.fit(X_train, y_train)

        # Predict
        y_pred_sliding[test_index] = estimator.predict(X_test)

    # Summary results
    output_dict = dict(
        times=times,
        y_all=y_all,
        y_pred_sliding=y_pred_sliding,
    )

    # Save results
    with open(os.path.join(RESULTS_FOLDER, f'{running_name}_sliding.pkl'),
              'wb') as f:
        pickle.dump(output_dict, f)

# %%