Beispiel #1
0
# -----------------
#
# Datasets can be specified in many ways: Each paradigm has a property
# 'datasets' which returns the datasets that are appropriate for that paradigm

print(LeftRightImagery().datasets)

##########################################################################
# Or you can run a search through the available datasets:
print(utils.dataset_search(paradigm="imagery", min_subjects=6))

##########################################################################
# Or you can simply make your own list (which we do here due to computational
# constraints)

dataset = BNCI2014001()
dataset.subject_list = dataset.subject_list[:2]
datasets = [dataset]

##########################################################################
# Paradigm
# --------------------
#
# Paradigms define the events, epoch time, bandpass, and other preprocessing
# parameters. They have defaults that you can read in the documentation, or you
# can simply set them as we do here. A single paradigm defines a method for
# going from continuous data to trial data of a fixed size. To learn more look
# at the tutorial Exploring Paradigms

fmin = 8
fmax = 35
Beispiel #2
0
from sklearn.linear_model import LogisticRegression as LR

from mne.decoding import CSP
from pyriemann.estimation import Covariances
from pyriemann.tangentspace import TangentSpace

import matplotlib.pyplot as plt
import moabb.analysis.plotting as moabb_plt

##############################################################################
# Datasets
# --------
#
# Select datasets for motor imagery

datasets = [Zhou2016(), BNCI2014001()]

##############################################################################
# Paradigm
# --------
#
# Restrict further analysis to specified channels, here C3, C4, and Cz.
# Also, use a specific resampling. In this example, all datasets are
# set to 200 Hz.

paradigm = LeftRightImagery(channels=['C3', 'C4', 'Cz'], resample=200.)

##############################################################################
# Evaluation
# ----------
#
# We instantiate the three different classiciation pipelines to be considered
# in the analysis. The object that gathers each pipeline is a dictionary. The
# first pipeline is the CSP+LDA that we have seen in the previous parts. The
# other two pipelines rely on Riemannian geometry, using an SVM classification
# in the tangent space of the covariance matrices estimated from the EEG or a
# MDM classifier that works directly on covariance matrices.
pipelines = {}
pipelines["csp+lda"] = make_pipeline(CSP(n_components=8), LDA())
pipelines["tgsp+svm"] = make_pipeline(Covariances('oas'),
                                      TangentSpace(metric='riemann'),
                                      SVC(kernel='linear'))
pipelines["MDM"] = make_pipeline(Covariances('oas'), MDM(metric='riemann'))

# The following lines go exactly as in the previous example, where we end up
# obtaining a pandas dataframe containing the results of the evaluation.
datasets = [BNCI2014001(), Weibo2014(), Zhou2016()]
paradigm = LeftRightImagery()
evaluation = WithinSessionEvaluation(paradigm=paradigm,
                                     datasets=datasets,
                                     overwrite=True)
results = evaluation.process(pipelines)
if not os.path.exists("./results"):
    os.mkdir("./results")
results.to_csv("./results/results_part2-3.csv")
results = pd.read_csv('./results/results_part2-3.csv')

##############################################################################
# Plotting Results
# ----------------
#
# The following plot shows a comparison of the three classification pipelines
Beispiel #4
0
# -----------------
#
# Datasets can be specified in many ways: Each paradigm has a property
# 'datasets' which returns the datasets that are appropriate for that paradigm

print(LeftRightImagery().datasets)

##########################################################################
# Or you can run a search through the available datasets:
print(utils.dataset_search(paradigm="imagery", min_subjects=6))

##########################################################################
# Or you can simply make your own list (which we do here due to computational
# constraints)

datasets = [BNCI2014001()]

##########################################################################
# Paradigm
# --------------------
#
# Paradigms define the events, epoch time, bandpass, and other preprocessing
# parameters. They have defaults that you can read in the documentation, or you
# can simply set them as we do here. A single paradigm defines a method for
# going from continuous data to trial data of a fixed size. To learn more look
# at the tutorial Exploring Paradigms

fmin = 8
fmax = 35
paradigm = LeftRightImagery(fmin=fmin, fmax=fmax)
# first pipeline is the CSP+LDA that we have seen in the previous parts. The
# other two pipelines rely on Riemannian geometry, using an SVM classification
# in the tangent space of the covariance matrices estimated from the EEG or a
# MDM classifier that works directly on covariance matrices.

pipelines = {}
pipelines["csp+lda"] = make_pipeline(CSP(n_components=8), LDA())
pipelines["tgsp+svm"] = make_pipeline(Covariances("oas"),
                                      TangentSpace(metric="riemann"),
                                      SVC(kernel="linear"))
pipelines["MDM"] = make_pipeline(Covariances("oas"), MDM(metric="riemann"))

##############################################################################
# The following lines go exactly as in the previous tutorial, where we end up
# obtaining a pandas dataframe containing the results of the evaluation.
datasets = [BNCI2014001(), Zhou2016()]
subj = [1, 2, 3]
for d in datasets:
    d.subject_list = subj
paradigm = LeftRightImagery()
evaluation = WithinSessionEvaluation(paradigm=paradigm,
                                     datasets=datasets,
                                     overwrite=False)
results = evaluation.process(pipelines)

##############################################################################
# As `overwrite` is set to False, the results from the previous tutorial are reused and
# only the new pipelines are evaluated. The results from "csp+lda" are not recomputed.
# The results are saved in ~/mne_data/results if the parameter `hdf5_path` is not set.

##############################################################################