Skip to content

Commit

Permalink
ENH/DEPR add new response_method and deprecate needs_* in make_scorer (
Browse files Browse the repository at this point in the history
…scikit-learn#26840)

Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
  • Loading branch information
3 people authored Oct 17, 2023
1 parent d91e1a5 commit e3d67d5
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 267 deletions.
12 changes: 9 additions & 3 deletions doc/modules/model_evaluation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ take several parameters:
of the python function is negated by the scorer object, conforming to
the cross validation convention that scorers return higher values for better models.

* for classification metrics only: whether the python function you provided requires continuous decision
certainties (``needs_threshold=True``). The default value is
False.
* for classification metrics only: whether the python function you provided requires
continuous decision certainties. If the scoring function only accepts probability
estimates (e.g. :func:`metrics.log_loss`) then one needs to set the parameter
`response_method`, thus in this case `response_method="predict_proba"`. Some scoring
function do not necessarily require probability estimates but rather non-thresholded
decision values (e.g. :func:`metrics.roc_auc_score`). In this case, one provides a
list such as `response_method=["decision_function", "predict_proba"]`. In this case,
the scorer will use the first available method, in the order given in the list,
to compute the scores.

* any additional parameters, such as ``beta`` or ``labels`` in :func:`f1_score`.

Expand Down
13 changes: 13 additions & 0 deletions doc/whats_new/v1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ Changelog
:func:`sklearn.metrics.zero_one_loss` now support Array API compatible inputs.
:pr:`27137` by :user:`Edoardo Abati <EdAbati>`.

- |API| Deprecated `needs_threshold` and `needs_proba` from :func:`metrics.make_scorer`.
These parameters will be removed in version 1.6. Instead, use `response_method` that
accepts `"predict"`, `"predict_proba"` or `"decision_function"` or a list of such
values. `needs_proba=True` is equivalent to `response_method="predict_proba"` and
`needs_threshold=True` is equivalent to
`response_method=("decision_function", "predict_proba")`.
:pr:`26840` by :user:`Guillaume Lemaitre <glemaitre>`.

- |Fix| Fixes a bug for metrics using `zero_division=np.nan`
(e.g. :func:`~metrics.precision_score`) within a paralell loop
(e.g. :func:`~model_selection.cross_val_score`) where the singleton for `np.nan`
Expand All @@ -371,6 +379,11 @@ Changelog
:func:`metrics.root_mean_squared_log_error` instead.
:pr:`26734` by :user:`Alejandro Martin Gil <101AlexMartin>`.

- |Fix| :func:`metrics.make_scorer` now raises an error when using a regressor on a
scorer requesting a non-thresholded decision function (from `decision_function` or
`predict_proba`). Such scorer are specific to classification.
:pr:`26840` by :user:`Guillaume Lemaitre <glemaitre>`.

:mod:`sklearn.model_selection`
..............................

Expand Down
Loading

0 comments on commit e3d67d5

Please sign in to comment.