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
{{ message }}
Repository navigation
sklearn.decomposition.PCA svd_solver='auto' should default to "arpack" for sparse input #7642
When using sklearn.decomposition.PCA on a scipy.sparse, the value provided in the svd_solver parameter must be "arpack" (which is the only algorithm supporting sparse input).
the default svd_solver value, "auto" presumes to pick an appropriate default value depending on other input parameters (such as matrix shape and n_components).
It would be helpful if "auto" will also take sparsity into consideration.
Additionally, svd_solver value "full" (or "auto" that picks "full") yields the following error:
TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.
It would be helpful if the error included a suggestion to use svd_solver value of "arpack" as a potential fix.
Actually, randomized should also work. Anything but full would be fine. So the "auto" method should be fixed (not sure if arpack or randomized is more appropriate as default) and the error message should be fixed as you indicated.
ping @giorgiop who knows all about the benchmarks ;)
D'oh. You should use TruncatedSVD and with any setting PCA should tell you not to use it with sparse data. The warning should tell you to use truncatedSVD though.
Activity
amueller commentedon Oct 11, 2016
Actually, randomized should also work. Anything but full would be fine. So the "auto" method should be fixed (not sure if arpack or randomized is more appropriate as default) and the error message should be fixed as you indicated.
ping @giorgiop who knows all about the benchmarks ;)
nirizr commentedon Oct 11, 2016
Did you mean "randomized" where you've used "full" in your previous message?
amueller commentedon Oct 11, 2016
@nirizr in one place, yes. I fixed it.
nirizr commentedon Oct 11, 2016
Actually, it looks like
sklearn.decomposition.PCAdoesn't nicely support sparse matrices as much as I'd hope.It ends up getting to this piece of code:
Which forces
Xto become dense.amueller commentedon Oct 11, 2016
D'oh. You should use TruncatedSVD and with any setting PCA should tell you not to use it with sparse data. The warning should tell you to use truncatedSVD though.
nirizr commentedon Oct 11, 2016
Oh, I didn't see that, thanks and sorry for the trouble!
amueller commentedon Oct 11, 2016
I guess we could provide a better error. PR welcome.
giorgiop commentedon Oct 12, 2016
Yeah, PCA should state clearly that it doesn't support sparse inputs. I am going to make a PR.
nirizr commentedon Oct 18, 2016
I guess this can be closed now?
Thank you @giorgiop!
giorgiop commentedon Oct 18, 2016
Yes. Thanks for spotting this!
nirizr commentedon Oct 18, 2016
Alright. closing. Thanks again guys!