Skip to content

(WIP) ENH Add zero_division = none or np.nan #22618

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

Closed
wants to merge 13 commits into from

Conversation

marctorsoc
Copy link
Contributor

Reference Issues/PRs

I checked and did not find any issue about this. This is an extension of my original PR #14900.

What does this implement/fix? Explain your changes.

This PR implements changes to allow zero_division to be None or np.nan. The objective is to:

  • return np.nan when the metric is undefined
  • ignore the undefined metric when averaging

This applies to precision, recall, f-score, and jaccard score.

As a byproduct of this:

  • Added a function _nan_average to get a combination of np.average and np. nanmean
  • Reformulated the computation of f-score in precision_recall_fscore_support see line 1665, to be as
    a function of TP, FP, FN rather than precision & recall. This makes more sense to me, but I'm happy to revert it.

Let me know what you think, and I'm open to any changes :)

Any other comments?

marctorsoc and others added 7 commits September 7, 2019 10:17
# Conflicts:
#	doc/whats_new/v0.21.rst
#	sklearn/metrics/classification.py
#	sklearn/metrics/tests/test_classification.py
- F-score only warns if both prec and rec are ill-defined
- new private method to simplify _prf_divide
# Conflicts:
#	sklearn/metrics/_classification.py
#	sklearn/metrics/tests/test_classification.py
- add weights casting to np.array
@marctorsoc marctorsoc changed the title ENH Add zero_division = none or np.nan (WIP) ENH Add zero_division = none or np.nan Feb 26, 2022
@marctorsoc marctorsoc closed this Apr 21, 2022
@marctorsoc marctorsoc deleted the zero_division_none branch January 20, 2023 20:07
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.

1 participant