Note
Go to the end to download the full example code.
Within Session SSVEP#
This Example shows how to perform a within-session SSVEP analysis on the MAMEM dataset 3, using a CCA pipeline.
The within-session evaluation assesses the performance of a classification pipeline using a 5-fold cross-validation. The reported metric (here, accuracy) is the average of all fold.
# Authors: Sylvain Chevallier <sylvain.chevallier@uvsq.fr>
#
# License: BSD (3-clause)
import warnings
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.pipeline import make_pipeline
import moabb
from moabb.datasets import Kalunga2016
from moabb.evaluations import WithinSessionEvaluation
from moabb.paradigms import SSVEP
from moabb.pipelines import SSVEP_CCA
warnings.simplefilter(action="ignore", category=FutureWarning)
warnings.simplefilter(action="ignore", category=RuntimeWarning)
moabb.set_log_level("info")
Loading Dataset#
Load 2 subjects of Kalunga2016 dataset
subj = [1, 3]
dataset = Kalunga2016()
dataset.subject_list = subj
Choose Paradigm#
We select the paradigm SSVEP, applying a bandpass filter (3-15 Hz) on the data and we keep only the first 3 classes, that is stimulation frequency of 13Hz, 17Hz and 21Hz.
Create Pipelines#
Use a Canonical Correlation Analysis classifier
Get Data (optional)#
To get access to the EEG signals downloaded from the dataset, you could use dataset.get_data(subjects=[subject_id]) to obtain the EEG under MNE format, stored in a dictionary of sessions and runs. Otherwise, paradigm.get_data(dataset=dataset, subjects=[subject_id]) allows to obtain the EEG data in scikit format, the labels and the meta information. In paradigm.get_data, the EEG are preprocessed according to the paradigm requirement.
# sessions = dataset.get_data(subjects=[3])
# X, labels, meta = paradigm.get_data(dataset=dataset, subjects=[3])
Evaluation#
The evaluation will return a DataFrame containing a single AUC score for each subject and pipeline.
overwrite = True # set to True if we want to overwrite cached results
evaluation = WithinSessionEvaluation(
paradigm=paradigm, datasets=dataset, suffix="examples", overwrite=overwrite
)
results = evaluation.process(pipeline)
print(results.head())
Kalunga2016-WithinSession: 0%| | 0/2 [00:00<?, ?it/s]
Kalunga2016-WithinSession: 50%|█████ | 1/2 [00:00<00:00, 2.49it/s]
0%| | 0.00/2.27M [00:00<?, ?B/s]
0%|▏ | 9.22k/2.27M [00:00<00:33, 67.7kB/s]
2%|▌ | 34.8k/2.27M [00:00<00:15, 146kB/s]
4%|█▍ | 84.0k/2.27M [00:00<00:08, 273kB/s]
8%|███ | 181k/2.27M [00:00<00:04, 503kB/s]
12%|████▌ | 263k/2.27M [00:00<00:03, 589kB/s]
16%|██████▏ | 361k/2.27M [00:00<00:02, 694kB/s]
25%|█████████▎ | 558k/2.27M [00:00<00:01, 1.05MB/s]
35%|█████████████▍ | 803k/2.27M [00:00<00:01, 1.42MB/s]
42%|███████████████▊ | 947k/2.27M [00:01<00:00, 1.39MB/s]
48%|█████████████████▋ | 1.09M/2.27M [00:01<00:00, 1.35MB/s]
54%|███████████████████▉ | 1.22M/2.27M [00:01<00:00, 1.32MB/s]
60%|██████████████████████ | 1.36M/2.27M [00:01<00:00, 1.28MB/s]
65%|████████████████████████▏ | 1.49M/2.27M [00:01<00:00, 1.25MB/s]
71%|██████████████████████████▎ | 1.61M/2.27M [00:01<00:00, 1.22MB/s]
76%|████████████████████████████▎ | 1.73M/2.27M [00:01<00:00, 1.20MB/s]
82%|██████████████████████████████▏ | 1.86M/2.27M [00:01<00:00, 1.17MB/s]
87%|████████████████████████████████▏ | 1.97M/2.27M [00:01<00:00, 1.14MB/s]
92%|██████████████████████████████████ | 2.09M/2.27M [00:02<00:00, 1.10MB/s]
97%|███████████████████████████████████▊ | 2.20M/2.27M [00:02<00:00, 1.06MB/s]
0%| | 0.00/2.27M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 2.27M/2.27M [00:00<00:00, 5.45GB/s]
0%| | 0.00/2.13M [00:00<?, ?B/s]
1%|▏ | 11.3k/2.13M [00:00<00:24, 85.4kB/s]
2%|▋ | 38.9k/2.13M [00:00<00:11, 177kB/s]
5%|█▋ | 96.3k/2.13M [00:00<00:06, 331kB/s]
7%|██▊ | 155k/2.13M [00:00<00:04, 410kB/s]
15%|█████▋ | 312k/2.13M [00:00<00:02, 778kB/s]
18%|███████▏ | 392k/2.13M [00:00<00:02, 764kB/s]
22%|████████▌ | 470k/2.13M [00:00<00:02, 749kB/s]
31%|███████████▋ | 656k/2.13M [00:00<00:01, 1.05MB/s]
36%|█████████████▌ | 762k/2.13M [00:01<00:01, 1.02MB/s]
41%|███████████████▊ | 865k/2.13M [00:01<00:01, 998kB/s]
47%|█████████████████▊ | 999k/2.13M [00:01<00:01, 1.07MB/s]
52%|███████████████████▏ | 1.11M/2.13M [00:01<00:00, 1.04MB/s]
57%|█████████████████████ | 1.21M/2.13M [00:01<00:00, 1.01MB/s]
62%|███████████████████████ | 1.33M/2.13M [00:01<00:00, 1.03MB/s]
67%|████████████████████████▊ | 1.43M/2.13M [00:01<00:00, 1.00MB/s]
72%|███████████████████████████▎ | 1.53M/2.13M [00:01<00:00, 977kB/s]
77%|█████████████████████████████ | 1.63M/2.13M [00:01<00:00, 954kB/s]
82%|██████████████████████████████▉ | 1.74M/2.13M [00:01<00:00, 964kB/s]
86%|████████████████████████████████▋ | 1.83M/2.13M [00:02<00:00, 942kB/s]
91%|██████████████████████████████████▍ | 1.93M/2.13M [00:02<00:00, 920kB/s]
96%|████████████████████████████████████▌ | 2.05M/2.13M [00:02<00:00, 965kB/s]
0%| | 0.00/2.13M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 2.13M/2.13M [00:00<00:00, 10.4GB/s]
Kalunga2016-WithinSession: 100%|██████████| 2/2 [00:06<00:00, 3.84s/it]
Kalunga2016-WithinSession: 100%|██████████| 2/2 [00:06<00:00, 3.32s/it]
score time samples ... n_sessions dataset pipeline
0 0.762222 0.038551 48.0 ... 1 Kalunga2016 CCA
1 0.917778 0.037791 48.0 ... 1 Kalunga2016 CCA
[2 rows x 9 columns]
Plot Results#
Here we plot the results, indicating the score for each subject
plt.figure()
sns.barplot(data=results, y="score", x="session", hue="subject", palette="viridis")

<Axes: xlabel='session', ylabel='score'>
And the computation time in seconds
plt.figure()
ax = sns.barplot(data=results, y="time", x="session", hue="subject", palette="Reds")
ax.set_ylabel("Time (s)")
plt.show()

Total running time of the script: (0 minutes 8.471 seconds)
Estimated memory usage: 313 MB