# CSP with rest state EEG data for predicting stage of	disease

**URL:** <https://mne.discourse.group/t/csp-with-rest-state-eeg-data-for-predicting-stage-of-disease/1940>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 29, 2019, 1:05am UTC](https://mne.discourse.group/t/csp-with-rest-state-eeg-data-for-predicting-stage-of-disease/1940 "2019-08-29T01:05:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 29, 2019, 1:05am UTC](https://mne.discourse.group/t/csp-with-rest-state-eeg-data-for-predicting-stage-of-disease/1940/1 "2019-08-29T01:05:51Z")

</div>

External Email - Use Caution

Greetings. Posted this question earlier but i needed to register with the  
list first. So, posting again.

I am trying to predict early and final stages of brain disease. I though i  
could use CSP for this task as i find some new papers in CSP that work with  
rest eeg data. Each instance (or patient whose eeg is taken) is a  
(19\*number of sampling time points) matrix. 19 is the number of channels. I  
do a train-test split of 70%-30%, eventually, would like to learn from a  
50-50% split. For each of the train and test sets, a band pass filter is  
applied for each frequency range and events are created with  
make\_fixed\_length\_events(). We tried 30s events with 15s overlap and  
lesser. I also tried 5s events with 2s overlaps and so on. Now,  
i understand that in resting state, no events are there actually but i did  
it this way to use the CSP API. Of course, all epochs for a given instance,  
in this case, is strictly binary (early/final)

A brief snapshot of my code is as follows:

# for each frequency band  
for freq, (fmin,fmax) in enumerate(freq\_ranges):  
&nbsp;&nbsp;&nbsp;&nbsp;# for each instance/patient  
&nbsp;&nbsp;&nbsp;&nbsp;for raw in trainrawarr:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;picks = pick\_types(raw.info, meg=False, eeg=True,  
stim=False,eog=False,exclude='bads')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw\_filter=raw.copy().filter(fmin, fmax, n\_jobs=-1,  
fir\_design="firwin")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;events=make\_fixed\_length\_events(raw\_filter, id=1,duration=30.,  
overlap=15.)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;epochs=Epochs(raw\_filter, events, picks=picks)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# epochs contains a 3d array, (number of epochs, 19, number of time  
points)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# all epochs in this instance are 1 or 0 indicating stage of disease.

We repeat the above for the testrawarr also.

I use sklearn GridSearch with KFoldK=2,5,10 using different classifiers  
with parameter tuning, such as lda, qda, decision tree,svc, knn. The  
training roc\_auc is either very poor or very good. Test ROC is less than  
50%. I use the np.vstack() method to concatenate all the 3 dimensional  
epochs in train or test.

csp=CSP(reg=None, log=True, norm\_trace=False, cov\_est="epoch")  
param\_grid\_lda = [{'lda\_\_solver': ['lsqr'], 'lda\_\_shrinkage': [0.0001,  
0.001, 0.010, 0.1, 1], 'csp\_\_n\_components': [5,10, 20, 30],  
'csp\_\_reg':[0.00001, 0.0001,0.001,0.01,0.1,1] }]  
for freq in range(8): # there are 8 frequency bands  
&nbsp;&nbsp;&nbsp;&nbsp;for split in [5,10]:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("Evaluating cv split: ", split, " in freq range:  
",freq\_ranges[freq])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clf=Pipeline([('csp', csp), ('lda', lda)])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;search=GridSearchCV(clf,

cv=StratifiedKFold(split),param\_grid=param\_grid\_lda,scoring='roc\_auc',  
n\_jobs=-1)

model=search.fit(np.vstack(epochs\_all\_freq\_ranges[freq]),epoch\_labels[freq])

testpred=search.predict(np.vstack(test\_epochs\_all\_freq\_ranges[freq]))

Can someone please explain what is wrong with this code or approach ?Would  
be really helpful. I noticed similar questions, especially this
