# can not do csp.fit\_transform() without label

**URL:** <https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072>\
**Category:** Support & Discussions\
**Tags:** machine-learning, csp\
**Created:** [December 3, 2021, 9:20am UTC](https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072 "2021-12-03T09:20:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Long](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/long/32/374_2.png) [@Long](https://mne.discourse.group/u/Long)\
**Post date:** [December 3, 2021, 9:20am UTC](https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072/1 "2021-12-03T09:20:18Z")

</div>

I am usng MNE 0.23.4;  
I am following this tutorial about CSP: [mne.decoding.CSP — MNE 0.24.1 documentation](https://mne.tools/stable/generated/mne.decoding.CSP.html#mne.decoding.CSP.fit_transform)  
When I do: a=csp.fit\_transform(epochs\_data\_train), I got complain like below:

```python
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/long/anaconda/envs/3.6/lib/python3.6/site-packages/mne/decoding/mixin.py", line 30, in fit_transform
    return self.fit(X, **fit_params).transform(X)
TypeError: fit() missing 1 required positional argument: 'y'

```

However, in the doc, it says ‘y’ is optional, could be set as y=None, as in [mne.decoding.CSP — MNE 0.24.1 documentation](https://mne.tools/stable/generated/mne.decoding.CSP.html#mne.decoding.CSP.fit_transform) . . Also in the paper titled ’ Common Spatial Pattern Method for Channel Selelction in Motor Imagery Based Brain-computer Interface’ by [Yijun Wang], they calculate CSP without using label.

Could you please help to clarify on this? Do I really need to feed my label to CSP because I am doing a regression task which I don’t have a label.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [December 3, 2021, 9:39am UTC](https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072/2 "2021-12-03T09:39:07Z")

</div>

Hello @Long,

this is actually an API and a “documentation bug”. My understanding, after looking at the code, is that `CSP.fit()` (and, hence, `CSP.fit_transform()`) cannot work without a `y` with fewer than two classes. So you’ll **have** to specify a `y` parameter.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [December 3, 2021, 9:47am UTC](https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072/3 "2021-12-03T09:47:50Z")

</div>

I have opened an issue report at [CSP.fit() requires y to work, however the parameter is optional in fit\_transform() · Issue #10079 · mne-tools/mne-python · GitHub](https://github.com/mne-tools/mne-python/issues/10079)

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [December 3, 2021, 9:53am UTC](https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072/4 "2021-12-03T09:53:55Z")

</div>

doc is maybe not ideal but CSP is a supervised learning method so you need y with you call a “fit”

Alex

---

<div class="post-metadata">

**Author:** ![Long](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/long/32/374_2.png) [@Long](https://mne.discourse.group/u/Long)\
**Post date:** [December 3, 2021, 10:39am UTC](https://mne.discourse.group/t/can-not-do-csp-fit-transform-without-label/4072/5 "2021-12-03T10:39:19Z")

</div>

Dear all,  
Thanks for clarifying on this.
