-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG + 1] Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression #8567
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
|
||
# A Ridge regression model using an alpha value equal to the ratio of lambda_ and alpha_ from | ||
# the Bayesian Ridge model must be identical | ||
brModel = BayesianRidge(compute_score=True).fit(X, y) |
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.
we don't use CamelCase for var names.
brModel -> br or br_model
same for rrModel
# the Bayesian Ridge model must be identical | ||
brModel = BayesianRidge(compute_score=True).fit(X, y) | ||
rrModel = Ridge(alpha=brModel.lambda_ / brModel.alpha_).fit(X, y) | ||
assert_almost_equal(rrModel.intercept_, brModel.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.
can you also test the coef_ ?
Implemented reviewer's suggestions:
|
Codecov Report
@@ Coverage Diff @@
## master #8567 +/- ##
==========================================
+ Coverage 95.48% 95.48% +<.01%
==========================================
Files 342 342
Lines 61013 61021 +8
==========================================
+ Hits 58259 58267 +8
Misses 2754 2754
Continue to review full report at Codecov.
|
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.
+1 for merge pending comment and approval from @agramfort
rr_model = Ridge(alpha=br_model.lambda_ / br_model.alpha_).fit(X, y) | ||
assert_array_almost_equal(rr_model.coef_, br_model.coef_) | ||
assert_almost_equal(rr_model.intercept_, br_model.intercept_) | ||
# Results before fix |
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.
Please remove this...
And a whatsnew entry... |
after what's new entry and cleanup +1 for MRG |
Addressed requested changes:
|
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.
Thanks for addressing the review!
thx @gedeck |
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
…ian ridge regression (scikit-learn#8567) * Return correct ridge parameter alpha_ and lambda_ for regression * Add test for coefficients and fix style * Move sklearn.utils.testing to a more reasonable position. * Make flake8 happy * Code cleanup and entry in whats_new.rst
Reference Issue
Fixes #8224
What does this implement/fix? Explain your changes.
In the original implementation, the
alpha_
andlambda_
were modified after calculation ofcoef_
and were therefore slightly wrong. The change moves the assignment to the object attributesself.alpha_
andself.lambda_
to right after the calculation ofcoef_
.Any other comments?
The test uses a comparison to the standard ridge regression. A ridge regression with a ridge parameter of
self.lambda_ / self.alpha_
must return an identical regression. In the test, we compare the calculated intercept of the Bayesian ridge regression with the standard ridge regression. Before the change, the intercepts were slightly different.