Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

API Adds predict_params for Pipeline proba delegates #19790

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
Apr 5, 2021

Conversation

crflynn
Copy link
Contributor

@crflynn crflynn commented Mar 31, 2021

Reference Issues/PRs

Implements some of the changes discussed in #12006.

What does this implement/fix? Explain your changes.

Extends the **predict_params functionality of Pipeline.predict to Pipeline.predict_proba and Pipeline.predict_log_proba.

Any other comments?

As noted in #12006, there is currently no use case for this within sklearn. However, given the extensibility of the library and implementations in lightgbm and xgboost it seems appropriate and provides a consistent signature across predict delegates.

I'd be happy to implement similar changes for the decision_function delegate as well if requested.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @crflynn !

Please add an entry to the change log at doc/whats_new/v1.0.rst with tag ||. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:.

@@ -456,7 +456,7 @@ def fit_predict(self, X, y=None, **fit_params):
return y_pred

@if_delegate_has_method(delegate='_final_estimator')
def predict_proba(self, X):
def predict_proba(self, X, **predict_params):
Copy link
Member

Choose a reason for hiding this comment

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

I know it is longer, but I slightly prefer:

Suggested change
def predict_proba(self, X, **predict_params):
def predict_proba(self, X, **predict_proba_params):

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your suggestion is more explicit, so I've made the changes.

@@ -513,7 +517,7 @@ def score_samples(self, X):
return self.steps[-1][-1].score_samples(Xt)

@if_delegate_has_method(delegate='_final_estimator')
def predict_log_proba(self, X):
def predict_log_proba(self, X, **predict_params):
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Suggested change
def predict_log_proba(self, X, **predict_params):
def predict_log_proba(self, X, **predict_log_proba_params):

@@ -459,6 +467,26 @@ def test_predict_with_predict_params():
assert pipe.named_steps['clf'].got_attribute


def test_predict_proba_with_predict_params():
Copy link
Member

Choose a reason for hiding this comment

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

We can update test_predict_with_predict_params above into the following:

@pytest.mark.parametrize("method_name", [
    "predict", "predict_proba", "predict_log_proba"
])
def test_predict_methods_with_predict_params(method_name):
    # tests that Pipeline passes predict_* to the final estimator
    # when predict_* is invoked
    pipe = Pipeline([('transf', Transf()), ('clf', DummyEstimatorParams())])
    pipe.fit(None, None)
    method = getattr(pipe, method_name)
    method(X=None, got_attribute=True)

    assert pipe.named_steps['clf'].got_attribute

This takes advantage of pytest.mark.parametrize to test all the methods at once.

@thomasjpfan thomasjpfan changed the title predict_params for Pipeline proba delegates ENH predict_params for Pipeline proba delegates Apr 3, 2021
@thomasjpfan thomasjpfan changed the title ENH predict_params for Pipeline proba delegates ENH Adds predict_params for Pipeline proba delegates Apr 3, 2021
@crflynn crflynn force-pushed the extend_predict_params branch from 1242b40 to dbae1ab Compare April 4, 2021 02:03
@crflynn
Copy link
Contributor Author

crflynn commented Apr 4, 2021

Please add an entry to the change log at doc/whats_new/v1.0.rst with tag ||. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:.

I assume you mean |API| tag here. If not, I'll adjust it.

@thomasjpfan thomasjpfan changed the title ENH Adds predict_params for Pipeline proba delegates API Adds predict_params for Pipeline proba delegates Apr 4, 2021
@thomasjpfan
Copy link
Member

I assume you mean |API| tag here. If not, I'll adjust it.

Yes, that is what I meant.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

@jnothman
Copy link
Member

jnothman commented Apr 5, 2021

Thanks @crflynn

@jnothman jnothman merged commit 1411232 into scikit-learn:main Apr 5, 2021
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.