MNE example《Motor imagery decoding from EEG data using the Common Spatial Pattern (CSP)》(个人理解,example地址 )
根据源地址所示代码,本人的一些理解和疑惑,欢迎一起讨论,同时希望大佬指点迷津 😃
Anaconda上代码——
import numpy as np
import matplotlib. pyplot as plt
from sklearn. pipeline import Pipeline
from sklearn. discriminant_analysis import LinearDiscriminantAnalysis
from sklearn. model_selection import ShuffleSplit, cross_val_score
from mne import Epochs, pick_types, events_from_annotations
from mne. channels import make_standard_montage
from mne. io import concatenate_raws, read_raw_edf
from mne. datasets import eegbci
from mne. decoding import CSP
print ( __doc__)
tmin, tmax = - 1 . , 4 .
event_id = dict ( hands= 2 , feet= 3 )
subject = 1
runs = [ 6 , 10 , 14 ]
raw_fnames = eegbci. load_data( subject, runs)
raw = concatenate_raws( [ read_raw_edf( f, preload= True ) for f in raw_fnames] )
print ( '>>>>>>>>>>>>>' , raw. ch_names)
eegbci. standardize( raw)
montage = make_standard_montage( 'standard_1005' )
raw. set_montage( montage)
print ( '***********' , raw. ch_names)
raw. rename_channels( lambda x: x. strip( '.' ) )
raw. filter ( 7 . , 30 . , fir_design= 'firwin' , skip_by_annotation= 'edge' )
events, _ = events_from_annotations( raw, event_id= dict ( T1= 2 , T2= 3 ) )
picks = pick_types( raw. info, meg= False , eeg= True , stim= False , eog= False ,
exclude= 'bads' )
epochs = Epochs( raw, events, event_id, tmin, tmax, proj= True , picks= picks,
baseline= None , preload= True )
epochs_train = epochs. copy( ) . crop( tmin= 1 . , tmax= 2 . )
labels = epochs. events[ : , - 1 ] - 2
scores = [ ]
epochs_data = epochs. get_data( )
epochs_data_train = epochs_train. get_data( )
cv = ShuffleSplit( 10 , test_size= 0.2 , random_state= 42 )
cv_split = cv. split( epochs_data_train)
lda = LinearDiscriminantAnalysis( )
csp = CSP( n_components= 4 , reg= None , log=