-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FEA Add positive argument to Ridge using L-BFGS-B solver #20231
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
Conversation
@tnakae Thanks for working on this! I'll try to review. |
Could you please add a test that checks that it converge to the same solution with Something like: >>> import numpy as np
>>> rng = np.random.RandomState(42)
>>> X = rng.randn(300, 100)
>>> true_coef = rng.uniform(0.1, 1, size=X.shape[1])
>>> y = X @ true_coef + 1 + rng.normal(X.shape[0]) / 10
>>> from sklearn.linear_model import Ridge
>>> Ridge().fit(X, y).coef_
array([0.8425452 , 0.88417954, 0.48863294, 0.43436882, 0.65071889,
0.1547429 , 0.72064224, 0.80411708, 0.45595553, 0.25229772,
...
0.29870553, 0.10603551, 0.69988191, 0.82548552, 0.33983739]) |
@ogrisel Added test based on your comment! |
Thanks. I have another test idea: try to fit such a This last point is similar to the idea I suggested in #19615 to use the |
Out of curiosity could you also please benchmark the solver on a medium size dataset and compare to the speed of the solvers used for It would also be interesting to see a screenshot of the output of a profiling run with https://pypi.org/project/viztracer/ just to make sure that there is no unexpected performance problem. |
54ccb3f
to
45b0aae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorentzenchr or @rth final pass?
thx @tnakae !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good work! Thank you @tnakae
I had only a few comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing is to test _solve_lbfgs
directly against another solver for positive=False
.
Added test function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@tnakae Thanks again. This was a pleasant review experience on my side. Looking forward for the next one:smirk: |
FEA Add positive argument to Ridge using L-BFGS-B solver (scikit-learn#20231)
great work @tnakae ! |
Reference Issues/PRs
Fixes #19772 (Add positive argument to Ridge regression)
What does this implement/fix? Explain your changes.
lbfgs
solver to Ridge regression.L-BFGS-B
solver is used for constrained optimization.lsq_linear
was proposed In the discussion in issue Add positive argument to Ridge regression #19772,it was found that
lsq_linear
was much slower thanL-BFGS-B
.positive
argument to Ridge regression.True
, forces the coefficients to be positive (default value isFalse
)lbfgs
solver is supportedpositive=True
argument.positive=True
andsolver="auto"
,lbfgs
solver is automatically used.