Skip to content

[MRG] FIX bug in nested set_params usage #9999

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
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
4 changes: 4 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ Decomposition, manifold learning and clustering
with large datasets when ``n_components='mle'`` on Python 3 versions.
:issue:`9886` by :user:`Hanmin Qin <qinhanmin2014>`.

- Fixed a bug when setting parameters on meta-estimator, involving both a
wrapped estimator and its parameter. :issue:`9999` by :user:`Marcus Voss
<marcus-voss>` and `Joel Nothman`_.

Metrics

- Fixed a bug due to floating point error in :func:`metrics.roc_auc_score` with
Expand Down
1 change: 1 addition & 0 deletions sklearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def set_params(self, **params):
nested_params[key][sub_key] = value
else:
setattr(self, key, value)
valid_params[key] = value

for key, sub_params in nested_params.items():
valid_params[key].set_params(**sub_params)
Expand Down
8 changes: 8 additions & 0 deletions sklearn/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ def set_params(self, **kwargs):
estimator__min_samples_leaf=2)


def test_set_params_updates_valid_params():
# Check that set_params tries to set SVC().C, not
# DecisionTreeClassifier().C
gscv = GridSearchCV(DecisionTreeClassifier(), {})
gscv.set_params(estimator=SVC(), estimator__C=42.0)
assert gscv.estimator.C == 42.0


def test_score_sample_weight():

rng = np.random.RandomState(0)
Expand Down