Scree Plot for PCA


I performed a PCA on my epoched data and now would like to create a scree plot from the components. For this, I am trying to follow this tutorial. For this, I need to run the follwing line of code to access the % of variance explained by each component:

pca = UnsupervisedSpatialFilter(PCA(.99))
X_pca = pca.fit_transform(epochs_filt_data)
var_explained = pca.explained_variance_ratio_

This returns the following error:

AttributeError: 'UnsupervisedSpatialFilter' object has no attribute 'explained_variance_ratio_'

How can I access explained_variance_ratio instead?

Hello @tempMEG,

can you please provide a minimal working example so others have something to work with?


Yes ofc! I just added two more lines to give the code more context. I sadly can’t provide the data though.

hi @tempMEG ,

no need to share the data. Just use a public dataset from mne.datasets and share a full script one can just execute. By doing this effort you allow us to answer more user support questions.


1 Like

Hi @tempMEG
The error tells you that .explained_variance_ratio_ is not available for UnsupervisedSpatialFilter class. This is because it is an attribute of sklearn PCA object that is stored somewhere inside the UnsupervisedSpatialFilter class.
Based on the docs I would suggest to use .get_params() method to get the attributes of the PCA object.