Note
Go to the end to download the full example code.
Examples of analysis of a Dreyer2023 A dataset.#
This example shows how to plot Dreyer2023A Left-Right Imagery ROC AUC scores obtained with CSP+LDA pipeline versus demographic information of the examined subjects (gender and age) and experimenters (gender).
To reduce computational time, the example is provided for four subjects.
# Authors: Sara Sedlar <sara.sedlar@gmail.com>
# Sylvain Chevallier <sylvain.chevallier@universite-paris-saclay.fr>
# License: BSD (3-clause)
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import seaborn as sb
from pyriemann.estimation import Covariances
from pyriemann.spatialfilters import CSP
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
from sklearn.pipeline import make_pipeline
from moabb.datasets import Dreyer2023A
from moabb.evaluations import WithinSessionEvaluation
from moabb.paradigms import MotorImagery
Defining dataset, selecting subject for analysis and getting data
dreyer2023 = Dreyer2023A()
dreyer2023.subject_list = [1, 5, 7, 35]
dreyer2023.get_data()
0it [00:00, ?it/s]
9it [00:00, 9654.41it/s]
0it [00:00, ?it/s]
9it [00:00, 11586.48it/s]
0it [00:00, ?it/s]
9it [00:00, 11745.10it/s]
0it [00:00, ?it/s]
9it [00:00, 11767.06it/s]
{1: {'0': {'0R1acquisition': <RawEDF | sub-01_task-R1acquisition_eeg.edf, 32 x 230400 (450.0 s), ~56.3 MiB, data loaded>, '1R2acquisition': <RawEDF | sub-01_task-R2acquisition_eeg.edf, 32 x 230400 (450.0 s), ~56.3 MiB, data loaded>, '2R3online': <RawEDF | sub-01_task-R3online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '3R4online': <RawEDF | sub-01_task-R4online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '4R5online': <RawEDF | sub-01_task-R5online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '5R6online': <RawEDF | sub-01_task-R6online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>}}, 5: {'0': {'0R1acquisition': <RawEDF | sub-05_task-R1acquisition_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '1R2acquisition': <RawEDF | sub-05_task-R2acquisition_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '2R3online': <RawEDF | sub-05_task-R3online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '3R4online': <RawEDF | sub-05_task-R4online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '4R5online': <RawEDF | sub-05_task-R5online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '5R6online': <RawEDF | sub-05_task-R6online_eeg.edf, 32 x 234496 (458.0 s), ~57.3 MiB, data loaded>}}, 7: {'0': {'0R1acquisition': <RawEDF | sub-07_task-R1acquisition_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '1R2acquisition': <RawEDF | sub-07_task-R2acquisition_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '2R3online': <RawEDF | sub-07_task-R3online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '3R4online': <RawEDF | sub-07_task-R4online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '4R5online': <RawEDF | sub-07_task-R5online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '5R6online': <RawEDF | sub-07_task-R6online_eeg.edf, 32 x 230400 (450.0 s), ~56.3 MiB, data loaded>}}, 35: {'0': {'0R1acquisition': <RawEDF | sub-35_task-R1acquisition_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '1R2acquisition': <RawEDF | sub-35_task-R2acquisition_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '2R3online': <RawEDF | sub-35_task-R3online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '3R4online': <RawEDF | sub-35_task-R4online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '4R5online': <RawEDF | sub-35_task-R5online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>, '5R6online': <RawEDF | sub-35_task-R6online_eeg.edf, 32 x 230912 (451.0 s), ~56.4 MiB, data loaded>}}}
Defining MotorImagery paradigm and CSP+LDA pipeline
paradigm = MotorImagery()
pipelines = {}
pipelines["CSP+LDA"] = make_pipeline(
Covariances(estimator="oas"), CSP(nfilter=6), LDA(solver="lsqr", shrinkage="auto")
)
Within session evaluation of the pipeline
evaluation = WithinSessionEvaluation(
paradigm=paradigm, datasets=[dreyer2023], suffix="examples", overwrite=False
)
results = evaluation.process(pipelines)
0it [00:00, ?it/s]
9it [00:00, 10180.35it/s]
0it [00:00, ?it/s]
9it [00:00, 12284.00it/s]
0it [00:00, ?it/s]
9it [00:00, 12454.22it/s]
0it [00:00, ?it/s]
9it [00:00, 11859.48it/s]
Loading dataset info and concatenation with the obtained results
info = dreyer2023.get_subject_info().rename(columns={"score": "score_MR"})
# Creating a new column with subject's age
info["Age"] = 2019 - info["Birth_year"]
# Casting to int for merging
info["subject"] = info["SUJ_ID"].astype(int)
results["subject"] = results["subject"].astype(int)
results_info = results.merge(info, on="subject", how="left")
0%| | 0.00/19.8k [00:00<?, ?B/s]
0%| | 0.00/19.8k [00:00<?, ?B/s]
100%|█████████████████████████████████████| 19.8k/19.8k [00:00<00:00, 92.2MB/s]
5.1 Plotting subject AUC ROC scores vs subject’s gender
fig, ax = plt.subplots(nrows=2, ncols=2, facecolor="white", figsize=[16, 8], sharey=True)
fig.subplots_adjust(wspace=0.0, hspace=0.5)
sb.boxplot(
data=results_info, y="score", x="SUJ_gender", ax=ax[0, 0], palette="Set1", width=0.3
)
sb.stripplot(
data=results_info,
y="score",
x="SUJ_gender",
ax=ax[0, 0],
palette="Set1",
linewidth=1,
edgecolor="k",
size=3,
alpha=0.3,
zorder=1,
)
ax[0, 0].set_title("AUC ROC scores vs. subject gender")
ax[0, 0].set_xticklabels(["Man", "Woman"])
ax[0, 0].set_ylabel("ROC AUC")
ax[0, 0].set_xlabel(None)
ax[0, 0].set_ylim(0.3, 1)

(0.3, 1.0)
5.2 Plotting subject AUC ROC scores vs subjects’s age per gender
sb.regplot(
data=results_info[results_info["SUJ_gender"] == 1][["score", "Age"]].astype(
"float32"
),
y="score",
x="Age",
ax=ax[0, 1],
scatter_kws={"color": "#e41a1c", "alpha": 0.5},
line_kws={"color": "#e41a1c"},
)
sb.regplot(
data=results_info[results_info["SUJ_gender"] == 2][["score", "Age"]].astype(
"float32"
),
y="score",
x="Age",
ax=ax[0, 1],
scatter_kws={"color": "#377eb8", "alpha": 0.5},
line_kws={"color": "#377eb8"},
)
ax[0, 1].set_title("AUC ROC scores vs. subject age per gender")
ax[0, 1].set_ylabel(None)
ax[0, 1].set_xlabel(None)
ax[0, 1].legend(
handles=[
mpatches.Patch(color="#e41a1c", label="Man"),
mpatches.Patch(color="#377eb8", label="Woman"),
]
)
<matplotlib.legend.Legend object at 0x7fd8baa72aa0>
5.3 Plotting subject AUC ROC scores vs experimenter’s gender
sb.boxplot(
data=results_info, y="score", x="EXP_gender", ax=ax[1, 0], palette="Set1", width=0.3
)
sb.stripplot(
data=results_info,
y="score",
x="EXP_gender",
ax=ax[1, 0],
palette="Set1",
linewidth=1,
edgecolor="k",
size=3,
alpha=0.3,
zorder=1,
)
ax[1, 0].set_title("AUC ROC scores vs. experimenter gender")
ax[1, 0].set_xticklabels(["Man", "Woman"])
ax[1, 0].set_ylabel("ROC AUC")
ax[1, 0].set_xlabel(None)
ax[1, 0].set_ylim(0.3, 1)
(0.3, 1.0)
5.4 Plotting subject AUC ROC scores vs subject’s age
5.5 Obtained results for four selected subjects correspond to the following figure.#
Obtained results for all subjects correspond to the following figure.
Total running time of the script: (1 minutes 15.887 seconds)
Estimated memory usage: 2396 MB