# EEG redundancy data reduction based on N-dimensional	PCA

**URL:** <https://mne.discourse.group/t/eeg-redundancy-data-reduction-based-on-n-dimensional-pca/1444>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [March 1, 2018, 5:52am UTC](https://mne.discourse.group/t/eeg-redundancy-data-reduction-based-on-n-dimensional-pca/1444 "2018-03-01T05:52:13Z")\
**Posts on this page:** 3\
**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:** [March 1, 2018, 5:52am UTC](https://mne.discourse.group/t/eeg-redundancy-data-reduction-based-on-n-dimensional-pca/1444/1 "2018-03-01T05:52:13Z")

</div>

Dear MNE Group,

I am currently working on MNE for Neuro-feedback application. I would like to use PCA for dimensional EEG data reduction.

I followed the workflow explain in the example:

epochs = mne.Epochs(eeg\_channels, events=events, event\_id=event\_id, tmin=-0.2, tmax=0.5, proj=True, baseline=(None, 0), preload=True)

X=epochs.get\_data()

pca = UnsupervisedSpatialFilter(PCA(19), average=False)

pca = PCA(n\_components=None, whiten=False)

pca\_data = pca.fit\_transform(X)

pca\_reduced=pca.transform(X)

Error:

ValueError: Found array with dim 3. Estimator expected \<= 2.

Any help would be highly appreciated.

Thanks With Warm Regards,

MD. KHORSHED ALAM (Shishir)

Graduate Research Assistant (GRA)

Center of Intelligent Signal and Imaging Research (CISIR)  
Department of Electrical and Electronic Engineering  
Universiti Teknologi PETRONAS  
Bandar Seri Iskandar  
32610 Tronoh  
Perak Darul Ridzuan  
Malaysia

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20180301/c495f36a/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180301/c495f36a/attachment-0001.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:** [March 1, 2018, 7:08am UTC](https://mne.discourse.group/t/eeg-redundancy-data-reduction-based-on-n-dimensional-pca/1444/2 "2018-03-01T07:08:19Z")

</div>

Dear Khorshed Alam,

try this:

epochs = mne.Epochs(eeg\_channels, events=events, event\_id=event\_id, tmin=-0.2, tmax=0.5, proj=True, baseline=(None, 0), preload=True)  
n\_components = 19 # Number of components to keep (should be less then the number of channels)  
X = epochs.get\_data()  
pca = UnsupervisedSpatialFilter(PCA(n\_components, whiten=True), average=False)  
pca\_data = pca.fit\_transform(X)

best,  
Marijn.

the PCA expects a 2-dimensional data matrix: channels x

> Dear MNE Group,
> 
> I am currently working on MNE for Neuro-feedback application. I would like to use PCA for dimensional EEG data reduction.
> 
> I followed the workflow explain in the example:
> 
> epochs = mne.Epochs(eeg\_channels, events=events, event\_id=event\_id, tmin=-0.2, tmax=0.5, proj=True, baseline=(None, 0), preload=True)
> 
> X=epochs.get\_data()
> 
> pca = UnsupervisedSpatialFilter(PCA(19), average=False)
> 
> pca = PCA(n\_components=None, whiten=False)
> 
> pca\_data = pca.fit\_transform(X)
> 
> pca\_reduced=pca.transform(X)
> 
> Error:
> 
> ValueError: Found array with dim 3. Estimator expected \<= 2.
> 
> Any help would be highly appreciated.
> 
> Thanks With Warm Regards,  
> MD. KHORSHED ALAM (Shishir)  
> Graduate Research Assistant (GRA)  
> Center of Intelligent Signal and Imaging Research (CISIR)  
> Department of Electrical and Electronic Engineering  
> Universiti Teknologi PETRONAS  
> Bandar Seri Iskandar  
> 32610 Tronoh  
> Perak Darul Ridzuan  
> Malaysia
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> 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)
> 
> The information in this e-mail is intended only for the person to whom it is  
> addressed. If you believe this e-mail was sent to you in error and the e-mail  
> contains patient information, please contact the Partners Compliance HelpLine at  
> [MyComplianceReport.com: Compliance and Ethics Reporting](http://www.partners.org/complianceline) . If the e-mail was sent to you in error  
> but does not contain patient information, please contact the sender and properly  
> dispose of the e-mail.

-------------- next part --------------  
A non-text attachment was scrubbed...  
Name: smime.p7s  
Type: application/pkcs7-signature  
Size: 1386 bytes  
Desc: not available  
Url : [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20180301/58d9c579/attachment.bin](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180301/58d9c579/attachment.bin)

---

<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:** [March 1, 2018, 7:09am UTC](https://mne.discourse.group/t/eeg-redundancy-data-reduction-based-on-n-dimensional-pca/1444/3 "2018-03-01T07:09:49Z")

</div>

Hi there,

Just quickly looking over the code, it looks as though you are overwriting  
`pca`. Within MNE, we have the `UnsupervisedSpatialFilter` that takes an  
estimator `PCA` as an argument. It can then fit/fit\_transform your data  
`epochs.get_data()` which has the dimensions (n\_epochs, channels, time).

It seems you did create this with the first `pca` step. However, it seems  
you then included an erroneous second step, which overwrites `pca` with  
sklearn PCA object, which expects the data in the shape (n\_samples,  
n\_features).

Try removing that second PCA step and see if it works.

HTH,
