this is a tutorial from MNe office webpage , I try to get though this and made some modifications

import the moudle:

import numpy as np 
import matplotlib.pyplot as plt 
from sklearn.model_selection import ShuffleSplit,cross_val_score
from sklearn.pipeline import Pipeline
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn import svm

from mne.io import read_raw_edf,concatenate_raws
from mne.decoding import CSP
from mne import Epochs, pick_types, find_events
from mne.datasets import eegbci 
from mne.channels import read_layout 

导入各种所需类

Read the data and preprocesing:

tmin,tmax=-1,4
event=dict(hands=1,foot=2) 注意 这里我换成了1和2类 也就是 hands 和1  具体是啥也不知道
subjects=1
runs=[6, 10 ,14]  数据储存

raw_fnames=eegbci.load_data(subjects,runs)
raw_data=[read_raw_edf(f,preload=True,stim_channel='auto')for f in raw_fnames]     
raw=concatenate_raws(raw_data)
raw.rename_channels(lambda x:x.strip('.'))  去掉chanles后面的那个点 不知道做这个有嘛用
raw.filter(7,30,fir_design='firwin2', skip_by_annotation='edge')  滤波

read the event and epoch the data

events=find_events(raw,shortest_event=0,stim_channel='STI 014')  读取事件
picks=pick_types(raw.info,meg=False,eeg=True,eog=False,stim=False) 选择数据
epoch=Epochs(raw,events,event,tmin,tmax,picks=picks,proj=True,baseline=None,preload=True ) 把数据epoch化

Data for Train and labels

epochs_train=epoch.copy().crop(tmin=1,tmax=2) 截取1-2秒的数据
labels=epoch.events[:,-1]-2                   修改label
score=[]
epoch_data=epoch.get_data()
epoch_data_train=epochs_train.get_data()       

cv=ShuffleSplit(10,test_size=0.2,random_state=42)  随机cv  
cv_split=cv.split(epoch_data_train)                 

Buld the classifier

lda=LinearDiscriminantAnalysis()  线性判别
svc=svm.SVC(kernel='rbf',C=0.5);  SVM 
csp=CSP(n_components=4,log=True, reg=None, norm_trace=False)  CSP算法

clf=Pipeline([('CSP',csp),('SVM',svc)])            sklean Pipleline
scores=cross_val_score(clf,epoch_data_train,labels,cv=cv,n_jobs=-1)   计算准确度

score  结果

array([ 0.84615385,  0.92307692,  0.92307692,  0.92307692,  0.84615385,
        0.69230769,  0.76923077,  0.92307692,  0.92307692,  0.84615385])

CSP patterns 特征
Download