8000 [MRG + 1] Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression by gedeck · Pull Request #8567 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[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

Merged
merged 5 commits into from
Mar 16, 2017

Conversation

gedeck
Copy link
Contributor
@gedeck gedeck commented Mar 10, 2017

Reference Issue

Fixes #8224

What does this implement/fix? Explain your changes.

In the original implementation, the alpha_ and lambda_ were modified after calculation of coef_ and were therefore slightly wrong. The change moves the assignment to the object attributes self.alpha_ and self.lambda_ to right after the calculation of coef_.

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.

    # ACTUAL: 2.422446078010811
    # DESIRED: 2.4224997161532529

@gedeck gedeck changed the title Return correct ridge parameter alpha_ and lambda_ for regression Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression Mar 10, 2017

# 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)
Copy link
Member

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_)
Copy link
Member

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_ ?

@gedeck
Copy link
Contributor Author
gedeck commented Mar 10, 2017

Implemented reviewer's suggestions:

  • Removed use of camel case for variable names.
  • Add tests for coefficients. They were also slightly different in the original implementation
 x: array([ 0.000774,  0.000859])
 y: array([ 0.000767,  0.000852])

@codecov
Copy link
codecov bot commented Mar 10, 2017

Codecov Report

Merging #8567 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #8567      +/-   ##
==========================================
+ Coverage   95.48%   95.48%   +<.01%     
==========================================
  Files         342      342              
  Lines       61013    61021       +8     
==========================================
+ Hits        58259    58267       +8     
  Misses       2754     2754
Impacted Files Coverage Δ
sklearn/linear_model/bayes.py 95.3% <100%> (ø)
sklearn/linear_model/tests/test_bayes.py 85.24% <100%> (+2.22%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34a3c99...b9a4b83. Read the comment docs.

Copy link
Member
@raghavrv raghavrv left a 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
8000 Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this...

@raghavrv raghavrv changed the title Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression [MRG] Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression Mar 13, 2017
@raghavrv raghavrv added the Bug label Mar 13, 2017
@raghavrv raghavrv requested a review from agramfort March 13, 2017 07:50
@raghavrv
Copy link
Member

And a whatsnew entry...

@agramfort
Copy link
Member

after what's new entry and cleanup +1 for MRG

@gedeck
Copy link
Contributor Author
gedeck commented Mar 13, 2017

Addressed requested changes:

  • Comment in test_bayes.py removed
  • Entry added to whats_new.rst

@gedeck gedeck closed this Mar 13, 2017
@gedeck gedeck reopened this Mar 13, 2017
Copy link
Member
@raghavrv raghavrv left a 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!

@raghavrv raghavrv changed the title [MRG] Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression [MRG + 1] Return correct ridge parameter alpha_ and lambda_ for Bayesian ridge regression Mar 13, 2017
@agramfort agramfort merged commit 668a24c into scikit-learn:master Mar 16, 2017
@agramfort
Copy link
Member

thx @gedeck

@Przemo10 Przemo10 mentioned this pull request Mar 17, 2017
herilalaina pushed a commit to herilalaina/scikit-learn that referenced this pull request Mar 26, 2017
…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
massich pushed a commit to massich/scikit-learn that referenced this pull request Apr 26, 2017
…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
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
…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
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
…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
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…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
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…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
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bayesian ridge regression - alpha and lambda values don't correspond to calculated coef
3 participants
0