Skip to content

[MRG+1] Ridgecv normalize #9302

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 2 commits into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,13 @@ Bug fixes
by :user:`Andre Ambrosio Boechat <boechat107>`, :user:`Utkarsh Upadhyay
<musically-ut>`, and `Joel Nothman`_.


- Add ``data_home`` parameter to
:func:`sklearn.datasets.fetch_kddcup99` by `Loic Esteve`_.

- Fix inconsistent results between :class:`linear_model.RidgeCV`
and :class:`linear_model.Ridge` when using ``normalize=True``
by `Alexandre Gramfort`_.

API changes summary
-------------------

Expand Down
3 changes: 2 additions & 1 deletion sklearn/linear_model/ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,8 @@ def fit(self, X, y, sample_weight=None):
raise ValueError("cv!=None and store_cv_values=True "
" are incompatible")
parameters = {'alpha': self.alphas}
gs = GridSearchCV(Ridge(fit_intercept=self.fit_intercept),
gs = GridSearchCV(Ridge(fit_intercept=self.fit_intercept,
normalize=self.normalize),
Copy link
Member Author

Choose a reason for hiding this comment

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

normalize was not passed here

parameters, cv=self.cv, scoring=self.scoring)
gs.fit(X, y, sample_weight=sample_weight)
estimator = gs.best_estimator_
Expand Down
11 changes: 11 additions & 0 deletions sklearn/linear_model/tests/test_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,16 @@ def _test_ridge_loo(filter_):
return ret


def _test_ridge_cv_normalize(filter_):
ridge_cv = RidgeCV(normalize=True, cv=3)
ridge_cv.fit(filter_(10. * X_diabetes), y_diabetes)

gs = GridSearchCV(Ridge(normalize=True), cv=3,
param_grid={'alpha': ridge_cv.alphas})
gs.fit(filter_(10. * X_diabetes), y_diabetes)
assert_equal(gs.best_estimator_.alpha, ridge_cv.alpha_)


def _test_ridge_cv(filter_):
ridge_cv = RidgeCV()
ridge_cv.fit(filter_(X_diabetes), y_diabetes)
Expand Down Expand Up @@ -462,6 +472,7 @@ def check_dense_sparse(test_func):
def test_dense_sparse():
for test_func in (_test_ridge_loo,
_test_ridge_cv,
_test_ridge_cv_normalize,
_test_ridge_diabetes,
_test_multi_ridge_diabetes,
_test_ridge_classifiers,
Expand Down