-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
fit_intercept in RidgeCV with sparse design matrix and gcv_mode='svd' #13325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Although scipy also uses an eigendecomposition to compute the SVD in the sparse case, they use a sparse eigensolver, which should be more performant. I'll write some stability and performance benchmarks and take a look. |
from what I understand scikit-learn/sklearn/linear_model/ridge.py Line 914 in 7389dba
If I can be of assistance, I am willing to work on comparing the performance of |
Sure, if you'd like to take this up, you're welcome to. |
thanks, I'll start working on a benchmark then. |
I've spoken with some core devs, and not checking the dimensions is wrong behavior. What remains to be seen from your benchmark is whether using the sparse eigen solver is always better than the dense solver (the matrix we get after multiplying is usually not sparse anymore, so this might not be the case). |
actually my point was that the method is switched to the dual, I started a draft for adding support for fitting an intercept when x is sparse and we use an svd https://github.com/jeromedockes/scikit-learn/tree/ridge_gcv_svd_sparse_x but it is not reviewable and only a draft |
and it seems that the problem of no intercept being fitted happens in many places. for example this script
produces this output for me:
I thought this issue had been fixed for Ridge by #5360, but it does not seem to |
After some thought, it makes sense to refuse using the SVD when X is sparse
An attempt at those two things (work in progress) in #13350 |
note that switching to eigen when X is sparse and n > p is not a good idea, as it allocates the gram matrix, which is dense and (possibly much) larger than X |
Currently the ridge with generalized cross-validation which uses an SVD of the
design matrix (the best when there are more samples than features) does not
support sparse design matrices.
this results in silently using an eigendecomposition of the Gram matrix when
gcv_mode is 'auto'
scikit-learn/sklearn/linear_model/ridge.py
Line 1031 in 7389dba
or raising an error when the user explicitly asked for svd
scikit-learn/sklearn/linear_model/ridge.py
Line 965 in 7389dba
would it be better to:
allow sparse design matrices and compute the SVD using scipy.sparse.linalg.LinearOperator
warn the user that 'eigen' is being used, which can be very inefficient when
n_samples is much larger than n_features, so that they can decide if it is
better to use 'eigen', cast X to a dense matrix, or turn to another mode of CV
than the generalized CV
The text was updated successfully, but these errors were encountered: