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

Skip to content

DOC Improve pos_label and labels in precison/recall/f1 and jaccard #27714

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 5 commits into from
Nov 4, 2023

Conversation

lucyleeow
Copy link
Member

@lucyleeow lucyleeow commented Nov 3, 2023

Reference Issues/PRs

Towards #10010 - removal of pos_label=None as it is ill-defined and inconsistently implemented.

What does this implement/fix? Explain your changes.

Documention of pos_labels=None in precision_recall_fscore_support seems to have been removed in this commit. Prior to v0.18 you needed to set pos_label=None if targets were binary but you wanted to use average != 'binary' (ref). Now pos_label is just ignored if average != 'binary', so you no longer need to worry about setting pos_label to any specific value. (The related functions f1_score / fbeta_score / precision_score / recall_score behave the same)

History of the similar jaccard_score was more difficult to track. pos_label was added in #13151 but there was never any mention of None option.

Implementation wise, all these functions will allow pos_label=None. pos_label is only used if average='binary' and in this case pos_label=None will raise an error.

This PR:

  • Removes None as pos_label option in f1_score docstring (the only function that still had None in its docstring)
  • Remove mention of pos_label=None in precision_recall_fscore_support docstring:

If ``pos_label is None`` and in binary classification, this function
returns the average precision, recall and F-measure if ``average``
is one of ``'micro'``, ``'macro'``, ``'weighted'`` or ``'samples'``.

and add clarifications about pos_label and labels params.

  • Add the above pos_label and labels explanation to the other 5 functions as well
  • Clarify the including/excluding labels labels param doc:

order if ``average is None``. Labels present in the data can be
excluded, for example to calculate a multiclass average ignoring a
majority negative class, while labels not present in the data will
result in 0 components in a macro average. For multilabel targets,

Looking at the commit this was added, the related addition to model_evaluation.rst seems to expand what the docstring above means so I've used this to clarify.

Any other comments?

tl;dr update pos_label and labels explanations in docstrings of the following 6 functions:

  • precision_recall_fscore_support / f1_score / fbeta_score / precision_score / recall_score
  • jaccard_score

@lucyleeow
Copy link
Member Author

cc @glemaitre

Copy link

github-actions bot commented Nov 3, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: b8f10b2. Link to the linter CI: here

@glemaitre glemaitre self-requested a review November 3, 2023 15:08
Jaccard similarity coefficient for `pos_label`. If `average` is not `'binary'`,
`pos_label` is ignored and scores for both classes are calculated, and averaged or
both returned (when `average=None`). Similarly, for :term:`multiclass` and
:term:`multilabel` targets, scores for all `labels` can be returned or use
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to remove "can be"

Copy link
Member Author

Choose a reason for hiding this comment

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

I've amended to not include "can be", hopefully it is better.

and F1 score for both classes are calculated and averaged or both returned (when
`average=None`). Similarly, for :term:`multiclass` and :term:`multilabel` targets,
F1 score for all `labels` can be returned or use `average` to specify the averaging
technique to be used. Use `labels` specify the labels to calculate F1 score for.
Copy link
Member

Choose a reason for hiding this comment

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

I am always wondering if it is more natural to say "compute" or "calculate" :) (you can change depending what you like better here and in other places)

label. For the :term:`binary` case, setting `average='binary'` will return
metrics for `pos_label`. If `average` is not `'binary'`, `pos_label` is ignored
and metrics for both classes are calculated, and averaged or both returned (when
`average=None`).Similarly, for :term:`multiclass` and :term:`multilabel` targets,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`average=None`).Similarly, for :term:`multiclass` and :term:`multilabel` targets,
`average=None`). Similarly, for :term:`multiclass` and :term:`multilabel` targets,

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

It looks much better @lucyleeow.

@lucyleeow lucyleeow added the Waiting for Second Reviewer First reviewer is done, need a second one! label Nov 4, 2023
@glemaitre
Copy link
Member

Going to merge this one since this is a DOC PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation module:metrics Waiting for Second Reviewer First reviewer is done, need a second one!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants