# CSP for Multi-Classification

**URL:** <https://mne.discourse.group/t/csp-for-multi-classification/1749>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [February 23, 2019, 10:58am UTC](https://mne.discourse.group/t/csp-for-multi-classification/1749 "2019-02-23T10:58:51Z")\
**Posts on this page:** 4\
**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:** [February 23, 2019, 10:58am UTC](https://mne.discourse.group/t/csp-for-multi-classification/1749/1 "2019-02-23T10:58:51Z")

</div>

External Email - Use Caution

Hi everyone,  
CSP (from mne.decoding import CSP) (Common Spatial Patterns) for  
Multi-Classification gives clearly worse accuracy than the binary  
classification. Would you suggest a better solution for the case of more  
than two classes? Maybe another kind of CSP? Another kind of Machine  
Learning methods? or even Deep Learning?  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20190223/c22e73b0/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190223/c22e73b0/attachment.html)

---

<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:** [February 23, 2019, 10:20pm UTC](https://mne.discourse.group/t/csp-for-multi-classification/1749/2 "2019-02-23T22:20:08Z")

</div>

External Email - Use Caution

Hi!

Could you please be more specific? What have you tried for the multi-class case (how many classes?) and which method yielded better results? Which performance metric did you consider? Which data (cross-validation)? CSP is a spatial filter, and you can train filters e.g. in a 1-vs-rest scheme.

Clemens

---

<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:** [February 24, 2019, 9:32pm UTC](https://mne.discourse.group/t/csp-for-multi-classification/1749/3 "2019-02-24T21:32:09Z")

</div>

External Email - Use Caution

Hi Clemens,  
Thank you very much for your quesitons. I tried 2,3,4,6, and 18 classes. I  
found out that the best accuracy is in case of 2 classes and that by  
increasing the number of classes the accuracy decreases.  
I used cross\_validation. for all cases (2,3,4,6, or 18 classes) Following  
is part of my code as I copied some from  
[https://mne-tools.github.io/0.13/auto\_examples/decoding/plot\_decoding\_csp\_eeg.html](https://mne-tools.github.io/0.13/auto_examples/decoding/plot_decoding_csp_eeg.html)

from mne.decoding import CSP  
from sklearn.cross\_validation import cross\_val\_score

X\_train, X\_test, y\_train, y\_test = train\_test\_split(my\_array, y,  
test\_size=0.25,random\_state=0)  
csp = CSP(n\_components=15, reg=None, log=True, norm\_trace=False)  
log\_reg = LogisticRegression()  
clf = Pipeline([('CSP', csp), ('Reg', log\_reg)])  
my\_score = cross\_val\_score(clf, X\_train, y\_train, cv=10, n\_jobs=1,  
scoring='accuracy')

Is it right this way for multi-classification? What would you suggest? What  
do you mean by CSP is a spatial filter, and you can train filters e.g. in  
a 1-vs-rest scheme

Many thanks for your kind help

El s?b., 23 feb. 2019 a las 23:20, Brunner, Clemens (  
clemens.brunner at uni-graz.at) (\<clemens.brunner at uni-graz.at\>) escribi?:

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;External Email - Use Caution
> 
> Hi!
> 
> Could you please be more specific? What have you tried for the multi-class  
> case (how many classes?) and which method yielded better results? Which  
> performance metric did you consider? Which data (cross-validation)? CSP is  
> a spatial filter, and you can train filters e.g. in a 1-vs-rest scheme.
> 
> Clemens
> 
> \*From:\* mne\_analysis-bounces at nmr.mgh.harvard.edu \<  
> mne\_analysis-bounces at nmr.mgh.harvard.edu\> \*On Behalf Of \*tr rt  
> \*Sent:\* Saturday, 23 February 2019 11:59  
> \*To:\* mne\_analysis at nmr.mgh.harvard.edu  
> \*Subject:\* [Mne\_analysis] CSP for Multi-Classification
> 
> \* External Email - Use Caution \*
> 
> Hi everyone,
> 
> CSP (from mne.decoding import CSP) (Common Spatial Patterns) for  
> Multi-Classification gives clearly worse accuracy than the binary  
> classification. Would you suggest a better solution for the case of more  
> than two classes? Maybe another kind of CSP? Another kind of Machine  
> Learning methods? or even Deep Learning?  
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Mne\_analysis mailing list  
> Mne\_analysis at nmr.mgh.harvard.edu  
> [Mne\_analysis Info Page](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20190224/feca6312/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190224/feca6312/attachment.html)

---

<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:** [February 25, 2019, 7:19am UTC](https://mne.discourse.group/t/csp-for-multi-classification/1749/4 "2019-02-25T07:19:06Z")

</div>

External Email - Use Caution

Hi!

If you use accuracy as your performance measure, note that the chance level depends on the number of classes (among other factors such as class balance). For 2 balanced classes, chance level is 50%, for 3 classes its 33.33%, for 4 classes 25%, and so on. Therefore, given equally well separable data, accuracy will decrease with increasing number of classes (but there are other definitions on how to average accuracy in the multi class case).

Here's a good summary of performance measures that might be helpful: [https://scikit-learn.org/stable/modules/model\_evaluation.html](https://scikit-learn.org/stable/modules/model_evaluation.html). You might want to try Cohen's kappa, which is 0 at chance level and 1 in the best case (irrespective of the number of classes you have).

CSP is not a classifier, it preprocesses the data so that the variance in one class is maximized vs. the other class. In the multi class case, CSP uses a 1-vs-rest scheme. All this happens automatically, so you don't have to worry about that. Your code looks good, you're correctly using a combination of CSP and a classifier.

Clemens
