You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a particular reason why classes such as PCA, TruncatedPCA do not store the singular values as instance variables after they have been computed? It would seem useful to store them since they are already computed so that they can be later accessed if need be. One use case would be to scale the right singular vectors by their singular values. I am happy to make the changes and push if there are no objections.
It should be possible to access the singular values directly as a class attribute (especially since it is computed anyways) rather than indirectly
By PCA instances i meant to include PCA, TruncatedPCA and others. While indirectly computing the singular values from PCA is straightforward using explained_variance_, it is not possible (to my reading) from TruncatedPCA whose calculation for the explained_variance_ is more convoluted.
It seems like IncrementalPCA already exposes a class attribute self.singular_values_, so it would make sense to expose a similar attribute in other PCA related classes as well.
I needed this in my work, so I fixed this issue and have sent a pull request. I added it to PCA, RandomizedPCA and TruncatedSVD.
It could also be added to SparsePCA, but the singular values are not computed in the fit, but only in the transform, so I left it out of my fix. They could be added to the fit, but that would increase the computational load of the fit method.
Activity
lesteve commentedon Jul 4, 2016
From a quick look at it, it looks like you can compute them from the
explained_variance_attribute.Sbeing the diagonal matrix with the singular values.dchandan commentedon Jul 4, 2016
True, but a few comments:
explained_variance_, it is not possible (to my reading) from TruncatedPCA whose calculation for theexplained_variance_is more convoluted.self.singular_values_, so it would make sense to expose a similar attribute in other PCA related classes as well.amueller commentedon Oct 13, 2016
I guess there is no harm in storing S.
ENH: Added the singular values to PCA by a singular_values_ instance …
ENH: Added the singular values to PCA by a singular_values_ instance …
tomlof commentedon Oct 17, 2016
I needed this in my work, so I fixed this issue and have sent a pull request. I added it to PCA, RandomizedPCA and TruncatedSVD.
It could also be added to SparsePCA, but the singular values are not computed in the fit, but only in the transform, so I left it out of my fix. They could be added to the fit, but that would increase the computational load of the fit method.