Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC Ensures that make_scorer passes numpydoc validation #22367

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 3 commits into from
Feb 9, 2022
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
46 changes: 23 additions & 23 deletions sklearn/metrics/_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ def make_scorer(
:func:`~sklearn.model_selection.cross_val_score`.
It takes a score function, such as :func:`~sklearn.metrics.accuracy_score`,
:func:`~sklearn.metrics.mean_squared_error`,
:func:`~sklearn.metrics.adjusted_rand_index` or
:func:`~sklearn.metrics.average_precision`
:func:`~sklearn.metrics.adjusted_rand_score` or
:func:`~sklearn.metrics.average_precision_score`
and returns a callable that scores an estimator's output.
The signature of the call is `(estimator, X, y)` where `estimator`
is the model to be evaluated, `X` is the data and `y` is the
Expand All @@ -604,52 +604,41 @@ def make_scorer(
----------
score_func : callable
Score function (or loss function) with signature
``score_func(y, y_pred, **kwargs)``.
`score_func(y, y_pred, **kwargs)`.

greater_is_better : bool, default=True
Whether score_func is a score function (default), meaning high is good,
or a loss function, meaning low is good. In the latter case, the
scorer object will sign-flip the outcome of the score_func.
Whether `score_func` is a score function (default), meaning high is
good, or a loss function, meaning low is good. In the latter case, the
scorer object will sign-flip the outcome of the `score_func`.

needs_proba : bool, default=False
Whether score_func requires predict_proba to get probability estimates
out of a classifier.
Whether `score_func` requires `predict_proba` to get probability
estimates out of a classifier.

If True, for binary `y_true`, the score function is supposed to accept
a 1D `y_pred` (i.e., probability of the positive class, shape
`(n_samples,)`).

needs_threshold : bool, default=False
Whether score_func takes a continuous decision certainty.
Whether `score_func` takes a continuous decision certainty.
This only works for binary classification using estimators that
have either a decision_function or predict_proba method.
have either a `decision_function` or `predict_proba` method.

If True, for binary `y_true`, the score function is supposed to accept
a 1D `y_pred` (i.e., probability of the positive class or the decision
function, shape `(n_samples,)`).

For example ``average_precision`` or the area under the roc curve
For example `average_precision` or the area under the roc curve
can not be computed using discrete predictions alone.

**kwargs : additional arguments
Additional parameters to be passed to score_func.
Additional parameters to be passed to `score_func`.

Returns
-------
scorer : callable
Callable object that returns a scalar score; greater is better.

Examples
--------
>>> from sklearn.metrics import fbeta_score, make_scorer
>>> ftwo_scorer = make_scorer(fbeta_score, beta=2)
>>> ftwo_scorer
make_scorer(fbeta_score, beta=2)
>>> from sklearn.model_selection import GridSearchCV
>>> from sklearn.svm import LinearSVC
>>> grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]},
... scoring=ftwo_scorer)

Notes
-----
If `needs_proba=False` and `needs_threshold=False`, the score
Expand All @@ -660,6 +649,17 @@ def make_scorer(
`needs_threshold=True`, the score function is supposed to accept the
output of :term:`decision_function` or :term:`predict_proba` when
:term:`decision_function` is not present.

Examples
--------
>>> from sklearn.metrics import fbeta_score, make_scorer
>>> ftwo_scorer = make_scorer(fbeta_score, beta=2)
>>> ftwo_scorer
make_scorer(fbeta_score, beta=2)
>>> from sklearn.model_selection import GridSearchCV
>>> from sklearn.svm import LinearSVC
>>> grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]},
... scoring=ftwo_scorer)
"""
sign = 1 if greater_is_better else -1
if needs_proba and needs_threshold:
Expand Down
1 change: 0 additions & 1 deletion sklearn/tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"sklearn.metrics._ranking.roc_curve",
"sklearn.metrics._ranking.top_k_accuracy_score",
"sklearn.metrics._regression.mean_pinball_loss",
"sklearn.metrics._scorer.make_scorer",
"sklearn.metrics.cluster._bicluster.consensus_score",
"sklearn.metrics.cluster._supervised.adjusted_mutual_info_score",
"sklearn.metrics.cluster._supervised.adjusted_rand_score",
Expand Down