-
-
Notifications
You must be signed in to change notification settings - Fork 26k
MNT Change LinearRegression default tol to not break behavior #30688
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
MNT Change LinearRegression default tol to not break behavior #30688
Conversation
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!
No need to backport to 1.6.X since #30521 was merged after the 1.6.0 release and the docstring mentions that the new |
test_linear_regression_sample_weights
The change to the test seems fine, but at the same time this means that there is a behaviour change in #30521, right? Maybe this should be mentioned in the changelog? |
Alternatively we can set the default tol to |
Reading more the issues and PRs leading to adding the So I think that we can change the default to 1e-6 now, which is harmless since it hasn't been released yet, to avoid the behavior change. We can consider changing the default later to match Ridge if we really want to but it doesn't feel necessary. |
Thanks for having a closer look! I don't have a strong opinion on what is preferable:
|
@ogrisel, @glemaitre what do you think ? |
Let's do the backward compat for now. My long term plan would be to align LinearRegression better with ridge but this will involve more work. |
@@ -72,7 +72,7 @@ def test_linear_regression_sample_weights( | |||
sample_weight = 1.0 + rng.uniform(size=n_samples) | |||
|
|||
# LinearRegression with explicit sample_weight | |||
reg = LinearRegression(fit_intercept=fit_intercept) | |||
reg = LinearRegression(fit_intercept=fit_intercept, tol=1e-16) |
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.
So I guess this is not needed if we go for backward-compat i.e. tol=1e-6
by default?
reg = LinearRegression(fit_intercept=fit_intercept, tol=1e-16) | |
reg = LinearRegression(fit_intercept=fit_intercept) |
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.
I would keep it anyway because it's kind of "lucky" that it works with a higher tol. The reason tol was added was because it made a sample weight test fail and this test is also checking sample weights. Those tests require good convergence.
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.
OK fair enough!
Let's merge this one, thanks! |
Fixes #30684
Now that LinearRegression has a tol parameter we need to set it to a low value if we want to compare with the exact solution.