Skip to content

Fix internal kwargs leakage in scorers (metrics._scorer) #31293

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ _configtest.o.d

# virtualenv from advanced installation guide
sklearn-env/
sklenv/

# Default JupyterLite content
jupyterlite_contents
Expand Down
9 changes: 8 additions & 1 deletion sklearn/metrics/_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,14 @@ def _score(self, method_caller, estimator, X, y_true, **kwargs):
)

scoring_kwargs = {**self._kwargs, **kwargs}
return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
# Filter out internal control parameters before passing to user function
filtered_kwargs = {
k: v
for k, v in scoring_kwargs.items()
if k not in {"needs_sample_weight", "response_method"}
}

return self._sign * self._score_func(y_true, y_pred, **filtered_kwargs)


@validate_params(
Expand Down