.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_cross_subject_ssvep.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_cross_subject_ssvep.py: =========================== Cross-Subject SSVEP =========================== This example shows how to perform a cross-subject analysis on an SSVEP dataset. We will compare two pipelines : - Riemannian Geometry - CCA We will use the SSVEP paradigm, which uses the AUC as metric. .. GENERATED FROM PYTHON SOURCE LINES 13-38 .. code-block:: default # Authors: Sylvain Chevallier # # License: BSD (3-clause) import warnings import matplotlib.pyplot as plt import pandas as pd import seaborn as sns from pyriemann.estimation import Covariances from pyriemann.tangentspace import TangentSpace from sklearn.linear_model import LogisticRegression from sklearn.pipeline import make_pipeline import moabb from moabb.datasets import SSVEPExo from moabb.evaluations import CrossSubjectEvaluation from moabb.paradigms import SSVEP, FilterBankSSVEP from moabb.pipelines import SSVEP_CCA, SSVEP_TRCA, ExtendedSSVEPSignal warnings.simplefilter(action="ignore", category=FutureWarning) warnings.simplefilter(action="ignore", category=RuntimeWarning) moabb.set_log_level("info") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'rocket' which already exists. mpl_cm.register_cmap(_name, _cmap) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'rocket_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'mako' which already exists. mpl_cm.register_cmap(_name, _cmap) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'mako_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'icefire' which already exists. mpl_cm.register_cmap(_name, _cmap) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'icefire_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'vlag' which already exists. mpl_cm.register_cmap(_name, _cmap) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'vlag_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'flare' which already exists. mpl_cm.register_cmap(_name, _cmap) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'flare_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'crest' which already exists. mpl_cm.register_cmap(_name, _cmap) /home/runner/work/moabb/moabb/.venv/lib/python3.9/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'crest_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) .. GENERATED FROM PYTHON SOURCE LINES 39-48 Loading Dataset --------------- We will load the data from the first 2 subjects of the ``SSVEP_Exo`` dataset and compare two algorithms on this set. One of the algorithms could only process class associated with a stimulation frequency, we will thus drop the resting class. As the resting class is the last defined class, picking the first three classes (out of four) allows to focus only on the stimulation frequency. .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: default n_subject = 2 dataset = SSVEPExo() dataset.subject_list = dataset.subject_list[:n_subject] interval = dataset.interval .. GENERATED FROM PYTHON SOURCE LINES 55-66 Choose Paradigm --------------- We define the paradigms (SSVEP, SSSVEP_TRCA and FilterBankSSVEP) and use the dataset SSVEPExo. The SSVEP paradigm applied a bandpass filter (10-25 Hz) on the data, SSVEP_TRCA applied a bandpass filter (1-110 Hz) which correspond to almost no filtering, while the FilterBankSSVEP paradigm uses as many bandpass filters as there are stimulation frequencies (here 2). For each stimulation frequency the EEG is filtered with a 1 Hz-wide bandpass filter centered on the frequency. This results in ``n_classes`` copies of the signal, filtered for each class, as used in the filterbank motor imagery paradigms. .. GENERATED FROM PYTHON SOURCE LINES 66-71 .. code-block:: default paradigm = SSVEP(fmin=10, fmax=25, n_classes=3) paradigm_TRCA = SSVEP(fmin=1, fmax=110, n_classes=3) paradigm_fb = FilterBankSSVEP(filters=None, n_classes=3) .. GENERATED FROM PYTHON SOURCE LINES 72-76 Classes are defined by the frequency of the stimulation, here we use the first two frequencies of the dataset, 13 and 17 Hz. The evaluation function uses a LabelEncoder, transforming them to 0 and 1 .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: default freqs = paradigm.used_events(dataset) .. GENERATED FROM PYTHON SOURCE LINES 80-89 Create Pipelines ---------------- Pipelines must be a dict of sklearn pipeline transformer. The first pipeline uses Riemannian geometry, by building an extended covariance matrices from the signal filtered around the considered frequency and applying a logistic regression in the tangent plane. The second pipeline relies on the above defined CCA classifier. The third pipeline relies on the TRCA algorithm. .. GENERATED FROM PYTHON SOURCE LINES 89-106 .. code-block:: default pipelines_fb = {} pipelines_fb["RG+LogReg"] = make_pipeline( ExtendedSSVEPSignal(), Covariances(estimator="lwf"), TangentSpace(), LogisticRegression(solver="lbfgs", multi_class="auto"), ) pipelines = {} pipelines["CCA"] = make_pipeline(SSVEP_CCA(interval=interval, freqs=freqs, n_harmonics=3)) pipelines_TRCA = {} pipelines_TRCA["TRCA"] = make_pipeline( SSVEP_TRCA(interval=interval, freqs=freqs, n_fbands=5) ) .. GENERATED FROM PYTHON SOURCE LINES 107-116 Evaluation ---------- The evaluation will return a DataFrame containing an accuracy score for each subject / session of the dataset, and for each pipeline. Results are saved into the database, so that if you add a new pipeline, it will not run again the evaluation unless a parameter has changed. Results can be overwritten if necessary. .. GENERATED FROM PYTHON SOURCE LINES 116-124 .. code-block:: default overwrite = False # set to True if we want to overwrite cached results evaluation = CrossSubjectEvaluation( paradigm=paradigm, datasets=dataset, overwrite=overwrite ) results = evaluation.process(pipelines) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0%| | 0.00/2.06M [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_cross_subject_ssvep.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_