Tutorial 0: Getting Started#

This tutorial takes you through a basic working example of how to use this codebase, including all the different components, up to the results generation. If you’d like to know about the statistics and plotting, see the next tutorial.

# Authors: Vinay Jayaram <vinayjayaram13@gmail.com>
#
# License: BSD (3-clause)

Introduction#

To use the codebase you need an evaluation and a paradigm, some algorithms, and a list of datasets to run it all on. You can find those in the following submodules; detailed tutorials are given for each of them.

import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import make_pipeline
from sklearn.svm import SVC

If you would like to specify the logging level when it is running, you can use the standard python logging commands through the top-level moabb module

import moabb
from moabb.datasets import BNCI2014_001, utils
from moabb.evaluations import CrossSessionEvaluation
from moabb.paradigms import LeftRightImagery
from moabb.pipelines.features import LogVariance

In order to create pipelines within a script, you will likely need at least the make_pipeline function. They can also be specified via a .yml file. Here we will make a couple pipelines just for convenience

Create pipelines#

We create two pipelines: channel-wise log variance followed by LDA, and channel-wise log variance followed by a cross-validated SVM (note that a cross-validation via scikit-learn cannot be described in a .yml file). For later in the process, the pipelines need to be in a dictionary where the key is the name of the pipeline and the value is the Pipeline object

pipelines = {}
pipelines["AM+LDA"] = make_pipeline(LogVariance(), LDA())
parameters = {"C": np.logspace(-2, 2, 10)}
clf = GridSearchCV(SVC(kernel="linear"), parameters)
pipe = make_pipeline(LogVariance(), clf)

pipelines["AM+SVM"] = pipe

Datasets#

Datasets can be specified in many ways: Each paradigm has a property ‘datasets’ which returns the datasets that are appropriate for that paradigm

/home/runner/work/moabb/moabb/moabb/datasets/fake.py:92: RuntimeWarning: Setting non-standard config type: "MNE_DATASETS_FAKEDATASET-IMAGERY-10-2--60-60--120-120--FAKE1-FAKE2-FAKE3--C3-CZ-C4_PATH"
  set_config(key, temp_dir)
/home/runner/work/moabb/moabb/moabb/datasets/fake.py:92: RuntimeWarning: Setting non-standard config type: "MNE_DATASETS_FAKEVIRTUALREALITYDATASET-P300-21-1--60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60-60--120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120-120--TARGET-NONTARGET--C3-CZ-C4_PATH"
  set_config(key, temp_dir)
[<moabb.datasets.bnci.BNCI2014_001 object at 0x7f5811ca0670>, <moabb.datasets.bnci.BNCI2014_004 object at 0x7f5811ca1030>, <moabb.datasets.beetl.Beetl2021_A object at 0x7f5811ca2d40>, <moabb.datasets.beetl.Beetl2021_B object at 0x7f5811ca1180>, <moabb.datasets.gigadb.Cho2017 object at 0x7f5811ca33a0>, <moabb.datasets.dreyer2023.Dreyer2023 object at 0x7f5811ca1ae0>, <moabb.datasets.dreyer2023.Dreyer2023A object at 0x7f5811ca1000>, <moabb.datasets.dreyer2023.Dreyer2023B object at 0x7f5811ca2d10>, <moabb.datasets.dreyer2023.Dreyer2023C object at 0x7f5811ca10f0>, <moabb.datasets.mpi_mi.GrosseWentrup2009 object at 0x7f5811ca1c00>, <moabb.datasets.Lee2019.Lee2019_MI object at 0x7f5811ca19c0>, <moabb.datasets.liu2024.Liu2024 object at 0x7f5811ca3cd0>, <moabb.datasets.physionet_mi.PhysionetMI object at 0x7f5811ca1480>, <moabb.datasets.schirrmeister2017.Schirrmeister2017 object at 0x7f5811ca0d30>, <moabb.datasets.bbci_eeg_fnirs.Shin2017A object at 0x7f5811ca24d0>, <moabb.datasets.stieger2021.Stieger2021 object at 0x7f5811ca2ad0>, <moabb.datasets.Weibo2014.Weibo2014 object at 0x7f5811ca3220>, <moabb.datasets.Zhou2016.Zhou2016 object at 0x7f5811ca2980>]

Or you can run a search through the available datasets:

print(utils.dataset_search(paradigm="imagery", min_subjects=6))
[<moabb.datasets.alex_mi.AlexMI object at 0x7f5811ca1ae0>, <moabb.datasets.bnci.BNCI2014_001 object at 0x7f5811ca14e0>, <moabb.datasets.bnci.BNCI2014_002 object at 0x7f5811ca3490>, <moabb.datasets.bnci.BNCI2014_004 object at 0x7f5811ca2c20>, <moabb.datasets.bnci.BNCI2015_001 object at 0x7f5811ca29b0>, <moabb.datasets.bnci.BNCI2015_004 object at 0x7f5811ca2c80>, <moabb.datasets.gigadb.Cho2017 object at 0x7f5811ca2350>, <moabb.datasets.dreyer2023.Dreyer2023 object at 0x7f5811ca11e0>, <moabb.datasets.dreyer2023.Dreyer2023A object at 0x7f5811ca1120>, <moabb.datasets.dreyer2023.Dreyer2023B object at 0x7f5811ca2620>, <moabb.datasets.dreyer2023.Dreyer2023C object at 0x7f5811ca2830>, <moabb.datasets.fake.FakeDataset object at 0x7f5811ca39d0>, <moabb.datasets.mpi_mi.GrosseWentrup2009 object at 0x7f5811ca1180>, <moabb.datasets.Lee2019.Lee2019_MI object at 0x7f5811ca0970>, <moabb.datasets.liu2024.Liu2024 object at 0x7f5811ca2b60>, <moabb.datasets.upper_limb.Ofner2017 object at 0x7f5811ca27d0>, <moabb.datasets.physionet_mi.PhysionetMI object at 0x7f5811ca2ce0>, <moabb.datasets.schirrmeister2017.Schirrmeister2017 object at 0x7f5811ca1540>, <moabb.datasets.bbci_eeg_fnirs.Shin2017A object at 0x7f5811ca10f0>, <moabb.datasets.bbci_eeg_fnirs.Shin2017B object at 0x7f5811ca34f0>, <moabb.datasets.stieger2021.Stieger2021 object at 0x7f5811ca2b30>, <moabb.datasets.Weibo2014.Weibo2014 object at 0x7f5811ca3a60>]

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

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

Evaluation#

An evaluation defines how the training and test sets are chosen. This could be cross-validated within a single recording, or across days, or sessions, or subjects. This also is the correct place to specify multiple threads.

evaluation = CrossSessionEvaluation(
    paradigm=paradigm, datasets=datasets, suffix="examples", overwrite=False
)
results = evaluation.process(pipelines)
/home/runner/work/moabb/moabb/moabb/analysis/results.py:95: RuntimeWarning: Setting non-standard config type: "MOABB_RESULTS"
  set_config("MOABB_RESULTS", osp.join(osp.expanduser("~"), "mne_data"))

BNCI2014-001-CrossSession:   0%|          | 0/2 [00:00<?, ?it/s]2025-09-10 16:00:08,470 INFO MainThread moabb.datasets.download MNE_DATA is not already configured. It will be set to default location in the home directory - /home/runner/mne_data
All datasets will be downloaded to this location, if anything is already downloaded, please move manually to this location
/home/runner/work/moabb/moabb/moabb/datasets/download.py:60: RuntimeWarning: Setting non-standard config type: "MNE_DATASETS_BNCI_PATH"
  set_config(key, get_config("MNE_DATA"))
/home/runner/work/moabb/moabb/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py:1064: InsecureRequestWarning: Unverified HTTPS request is being made to host 'lampx.tugraz.at'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(


  0%|                                              | 0.00/42.8M [00:00<?, ?B/s]

  0%|                                     | 8.19k/42.8M [00:00<12:45, 55.9kB/s]

  0%|                                      | 56.3k/42.8M [00:00<03:20, 213kB/s]

  0%|                                       | 104k/42.8M [00:00<02:42, 262kB/s]

  1%|▏                                      | 256k/42.8M [00:00<01:16, 558kB/s]

  1%|▍                                     | 552k/42.8M [00:00<00:39, 1.07MB/s]

  3%|▉                                    | 1.14M/42.8M [00:00<00:20, 2.05MB/s]

  5%|██                                   | 2.33M/42.8M [00:01<00:10, 3.96MB/s]

 10%|███▊                                 | 4.38M/42.8M [00:01<00:05, 7.06MB/s]

 15%|█████▍                               | 6.30M/42.8M [00:01<00:04, 8.83MB/s]

 19%|███████▏                             | 8.30M/42.8M [00:01<00:03, 10.2MB/s]

 24%|████████▊                            | 10.2M/42.8M [00:01<00:02, 11.1MB/s]

 30%|███████████▎                         | 13.0M/42.8M [00:01<00:02, 13.4MB/s]

 36%|█████████████▎                       | 15.4M/42.8M [00:01<00:01, 14.2MB/s]

 41%|███████████████▎                     | 17.7M/42.8M [00:02<00:01, 14.4MB/s]

 47%|█████████████████▎                   | 20.0M/42.8M [00:02<00:01, 14.8MB/s]

 53%|███████████████████▍                 | 22.5M/42.8M [00:02<00:01, 15.3MB/s]

 58%|█████████████████████▍               | 24.9M/42.8M [00:02<00:01, 15.4MB/s]

 64%|███████████████████████▌             | 27.2M/42.8M [00:02<00:01, 15.5MB/s]

 69%|█████████████████████████▋           | 29.7M/42.8M [00:02<00:00, 15.8MB/s]

 75%|███████████████████████████▋         | 32.1M/42.8M [00:02<00:00, 15.8MB/s]

 81%|█████████████████████████████▊       | 34.5M/42.8M [00:03<00:00, 15.8MB/s]

 86%|███████████████████████████████▉     | 36.9M/42.8M [00:03<00:00, 15.9MB/s]

 92%|█████████████████████████████████▉   | 39.3M/42.8M [00:03<00:00, 15.9MB/s]

 97%|███████████████████████████████████▉ | 41.6M/42.8M [00:03<00:00, 15.8MB/s]

  0%|                                              | 0.00/42.8M [00:00<?, ?B/s]
100%|██████████████████████████████████████| 42.8M/42.8M [00:00<00:00, 182GB/s]
/home/runner/work/moabb/moabb/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py:1064: InsecureRequestWarning: Unverified HTTPS request is being made to host 'lampx.tugraz.at'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(


  0%|                                              | 0.00/43.8M [00:00<?, ?B/s]

  0%|                                     | 8.19k/43.8M [00:00<12:52, 56.6kB/s]

  0%|                                      | 56.3k/43.8M [00:00<03:21, 217kB/s]

  0%|▏                                      | 153k/43.8M [00:00<01:44, 419kB/s]

  1%|▎                                      | 344k/43.8M [00:00<00:56, 771kB/s]

  2%|▋                                     | 736k/43.8M [00:00<00:29, 1.46MB/s]

  3%|█▎                                   | 1.51M/43.8M [00:00<00:15, 2.77MB/s]

  7%|██▌                                  | 3.06M/43.8M [00:01<00:07, 5.32MB/s]

 12%|████▍                                | 5.21M/43.8M [00:01<00:04, 8.31MB/s]

 16%|█████▊                               | 6.94M/43.8M [00:01<00:03, 9.42MB/s]

 20%|███████▌                             | 8.93M/43.8M [00:01<00:03, 10.6MB/s]

 25%|█████████                            | 10.8M/43.8M [00:01<00:02, 11.2MB/s]

 29%|██████████▋                          | 12.7M/43.8M [00:01<00:02, 11.7MB/s]

 33%|████████████▎                        | 14.5M/43.8M [00:01<00:02, 12.0MB/s]

 37%|█████████████▊                       | 16.4M/43.8M [00:02<00:02, 12.2MB/s]

 42%|███████████████▍                     | 18.2M/43.8M [00:02<00:02, 12.4MB/s]

 46%|█████████████████                    | 20.2M/43.8M [00:02<00:01, 12.7MB/s]

 50%|██████████████████▋                  | 22.1M/43.8M [00:02<00:01, 12.7MB/s]

 55%|████████████████████▎                | 24.0M/43.8M [00:02<00:01, 12.9MB/s]

 59%|█████████████████████▉               | 25.9M/43.8M [00:02<00:01, 13.0MB/s]

 64%|███████████████████████▌             | 27.9M/43.8M [00:02<00:01, 13.1MB/s]

 68%|█████████████████████████▏           | 29.8M/43.8M [00:03<00:01, 13.1MB/s]

 73%|██████████████████████████▊          | 31.8M/43.8M [00:03<00:00, 13.2MB/s]

 77%|████████████████████████████▍        | 33.7M/43.8M [00:03<00:00, 13.1MB/s]

 81%|██████████████████████████████       | 35.6M/43.8M [00:03<00:00, 13.2MB/s]

 86%|███████████████████████████████▋     | 37.5M/43.8M [00:03<00:00, 13.1MB/s]

 92%|██████████████████████████████████   | 40.4M/43.8M [00:03<00:00, 15.0MB/s]

 98%|████████████████████████████████████ | 42.7M/43.8M [00:03<00:00, 15.3MB/s]

  0%|                                              | 0.00/43.8M [00:00<?, ?B/s]
100%|██████████████████████████████████████| 43.8M/43.8M [00:00<00:00, 167GB/s]

BNCI2014-001-CrossSession:  50%|█████     | 1/2 [00:15<00:15, 15.78s/it]/home/runner/work/moabb/moabb/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py:1064: InsecureRequestWarning: Unverified HTTPS request is being made to host 'lampx.tugraz.at'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(


  0%|                                              | 0.00/43.1M [00:00<?, ?B/s]

  0%|                                     | 8.19k/43.1M [00:00<13:01, 55.1kB/s]

  0%|                                      | 56.3k/43.1M [00:00<03:23, 212kB/s]

  0%|▏                                      | 144k/43.1M [00:00<01:51, 383kB/s]

  1%|▎                                      | 329k/43.1M [00:00<00:59, 717kB/s]

  2%|▌                                     | 696k/43.1M [00:00<00:31, 1.34MB/s]

  3%|█▏                                   | 1.42M/43.1M [00:00<00:16, 2.54MB/s]

  7%|██▍                                  | 2.80M/43.1M [00:01<00:08, 4.70MB/s]

 12%|████▎                                | 4.98M/43.1M [00:01<00:04, 7.84MB/s]

 16%|█████▉                               | 6.92M/43.1M [00:01<00:03, 9.42MB/s]

 21%|███████▊                             | 9.06M/43.1M [00:01<00:03, 10.9MB/s]

 26%|█████████▌                           | 11.1M/43.1M [00:01<00:02, 11.7MB/s]

 31%|███████████▎                         | 13.2M/43.1M [00:01<00:02, 12.5MB/s]

 35%|█████████████                        | 15.3M/43.1M [00:01<00:02, 12.8MB/s]

 40%|██████████████▉                      | 17.4M/43.1M [00:02<00:01, 13.2MB/s]

 45%|████████████████▋                    | 19.4M/43.1M [00:02<00:01, 13.3MB/s]

 50%|██████████████████▍                  | 21.5M/43.1M [00:02<00:01, 13.5MB/s]

 56%|████████████████████▉                | 24.3M/43.1M [00:02<00:01, 15.1MB/s]

 62%|███████████████████████              | 26.8M/43.1M [00:02<00:01, 15.4MB/s]

 68%|████████████████████████▉            | 29.1M/43.1M [00:02<00:00, 15.4MB/s]

 73%|███████████████████████████▏         | 31.6M/43.1M [00:03<00:00, 15.8MB/s]

 79%|█████████████████████████████▎       | 34.1M/43.1M [00:03<00:00, 16.0MB/s]

 85%|███████████████████████████████▍     | 36.7M/43.1M [00:03<00:00, 16.4MB/s]

 91%|█████████████████████████████████▌   | 39.1M/43.1M [00:03<00:00, 16.4MB/s]

 97%|███████████████████████████████████▋ | 41.6M/43.1M [00:03<00:00, 16.4MB/s]

  0%|                                              | 0.00/43.1M [00:00<?, ?B/s]
100%|██████████████████████████████████████| 43.1M/43.1M [00:00<00:00, 168GB/s]
/home/runner/work/moabb/moabb/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py:1064: InsecureRequestWarning: Unverified HTTPS request is being made to host 'lampx.tugraz.at'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(


  0%|                                              | 0.00/44.2M [00:00<?, ?B/s]

  0%|                                     | 8.19k/44.2M [00:00<13:00, 56.6kB/s]

  0%|                                      | 56.3k/44.2M [00:00<03:22, 218kB/s]

  0%|▏                                      | 153k/44.2M [00:00<01:45, 419kB/s]

  1%|▎                                      | 352k/44.2M [00:00<00:55, 794kB/s]

  2%|▋                                     | 736k/44.2M [00:00<00:29, 1.46MB/s]

  3%|█▎                                   | 1.50M/44.2M [00:00<00:15, 2.75MB/s]

  7%|██▌                                  | 3.06M/44.2M [00:01<00:07, 5.32MB/s]

 13%|████▊                                | 5.73M/44.2M [00:01<00:04, 9.45MB/s]

 19%|██████▉                              | 8.24M/44.2M [00:01<00:03, 11.9MB/s]

 24%|████████▋                            | 10.4M/44.2M [00:01<00:02, 12.8MB/s]

 29%|██████████▌                          | 12.6M/44.2M [00:01<00:02, 13.5MB/s]

 34%|████████████▌                        | 15.0M/44.2M [00:01<00:02, 14.4MB/s]

 39%|██████████████▌                      | 17.4M/44.2M [00:01<00:01, 14.9MB/s]

 44%|████████████████▍                    | 19.6M/44.2M [00:02<00:01, 15.1MB/s]

 50%|██████████████████▎                  | 21.9M/44.2M [00:02<00:01, 15.3MB/s]

 55%|████████████████████▎                | 24.2M/44.2M [00:02<00:01, 15.4MB/s]

 60%|██████████████████████▏              | 26.5M/44.2M [00:02<00:01, 15.4MB/s]

 65%|████████████████████████             | 28.8M/44.2M [00:02<00:00, 15.5MB/s]

 70%|█████████████████████████▉           | 31.0M/44.2M [00:02<00:00, 15.4MB/s]

 75%|███████████████████████████▊         | 33.3M/44.2M [00:02<00:00, 15.5MB/s]

 81%|█████████████████████████████▊       | 35.6M/44.2M [00:03<00:00, 15.6MB/s]

 86%|███████████████████████████████▋     | 37.9M/44.2M [00:03<00:00, 15.5MB/s]

 91%|█████████████████████████████████▌   | 40.1M/44.2M [00:03<00:00, 15.6MB/s]

 96%|███████████████████████████████████▌ | 42.4M/44.2M [00:03<00:00, 15.6MB/s]

  0%|                                              | 0.00/44.2M [00:00<?, ?B/s]
100%|██████████████████████████████████████| 44.2M/44.2M [00:00<00:00, 137GB/s]

BNCI2014-001-CrossSession: 100%|██████████| 2/2 [00:29<00:00, 14.46s/it]
BNCI2014-001-CrossSession: 100%|██████████| 2/2 [00:29<00:00, 14.66s/it]
2025-09-10 16:00:37,542 INFO MainThread moabb.evaluations.base AM+LDA | BNCI2014-001 | 1 | 0train: Score 0.786
2025-09-10 16:00:37,657 INFO MainThread moabb.evaluations.base AM+LDA | BNCI2014-001 | 1 | 1test: Score 0.802
2025-09-10 16:00:37,772 INFO MainThread moabb.evaluations.base AM+SVM | BNCI2014-001 | 1 | 0train: Score 0.797
2025-09-10 16:00:37,907 INFO MainThread moabb.evaluations.base AM+SVM | BNCI2014-001 | 1 | 1test: Score 0.774
2025-09-10 16:00:38,037 INFO MainThread moabb.evaluations.base AM+LDA | BNCI2014-001 | 2 | 0train: Score 0.577
2025-09-10 16:00:38,152 INFO MainThread moabb.evaluations.base AM+LDA | BNCI2014-001 | 2 | 1test: Score 0.499
2025-09-10 16:00:38,270 INFO MainThread moabb.evaluations.base AM+SVM | BNCI2014-001 | 2 | 0train: Score 0.551
2025-09-10 16:00:38,399 INFO MainThread moabb.evaluations.base AM+SVM | BNCI2014-001 | 2 | 1test: Score 0.471

Results are returned as a pandas DataFrame, and from here you can do as you want with them

print(results.head())
      score      time  samples  ... n_sessions       dataset  pipeline
0  0.797068  0.151659    144.0  ...          2  BNCI2014-001    AM+SVM
1  0.773920  0.143207    144.0  ...          2  BNCI2014-001    AM+SVM
2  0.550733  0.245662    144.0  ...          2  BNCI2014-001    AM+SVM
3  0.471451  0.160652    144.0  ...          2  BNCI2014-001    AM+SVM
4  0.786458  0.031196    144.0  ...          2  BNCI2014-001    AM+LDA

[5 rows x 9 columns]

Total running time of the script: (0 minutes 31.727 seconds)

Estimated memory usage: 769 MB

Gallery generated by Sphinx-Gallery