FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
moabb/tutorials/plot_Getting_Started.py at develop · BCIPRO/moabb · GitHub
BCIPRO
moabb
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
moabb
/
tutorials
/
plot_Getting_Started.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
127 lines (100 loc) · 4.46 KB
Breadcrumbs
moabb
/
tutorials
/
plot_Getting_Started.py
Copy path
File metadata and controls
127 lines (100 loc) · 4.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""=========================
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
BNCI2014001
,
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
moabb
.
set_log_level
(
"info"
)
##############################################################################
# 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
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
()
#a = dataset.download()
#print(a)
dataset
.
subject_list
=
dataset
.
subject_list
[:
2
]
datasets
=
[
dataset
]
# print("----------------------")
# print(dataset.get_data()[1])
# print("----------------------")
# def xD:
# exit()
##########################################################################
# 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
)
##########################################################################
# 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
)
##########################################################################
# Results are returned as a pandas DataFrame, and from here you can do as you
# want with them
print
(
results
.
head
())
Back
|
FazBrowse Home
|
New Git URL