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
BUG fix behaviour in confusion_matrix with with empty array-like as input #16442
BUG fix behaviour in confusion_matrix with with empty array-like as input #16442
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the following:
- an entry to the change log at doc/whats_new/v0.23.rst under bug fixes. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:
- a similar test to check that
plot_confusion_matrix
is giving the appropriate result as well. The file is located insklearn/metrics/_plot/tests/test_plot_confusion_matrix.py
.
Co-Authored-By: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Co-Authored-By: Guillaume Lemaitre <g.lemaitre58@gmail.com>
…d' of github.com:parsons-kyle-89/scikit-learn into fix-confusion_matrix-0-observations-and-labels-specified
I wasn't quite sure what form such a test should have, but I copied the form of another test of text color. Let me know if you think there should be a more thorough test here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last changes otherwise LGTM.
I pushed my last comments and split one of the test which focus only on errors raised in |
@parsons-kyle-89 Thank for raising and contributing |
|
Reference Issues/PRs
Fixes #16432
What does this implement/fix? Explain your changes.
Currently on master
confusion_matrix
raises aValueError
wheny_true
andy_pred
are empty andlabels
is notNone
.With the change in this PR, the second case will return an nxn numpy array of zeros. This is correct with respect to the definition of confusion matrix given in the documentation.
Any other comments?
This change should be especially useful to users using
confusion_matrix
in automated reporting. Automated reports will sometimes (correctly) be run on datasets of size 0. In this case allowingconfusion_matrix
to correctly return an nxn matrix of zeros rather than raising will eliminate the need for the user to write a special case.