Skip to content
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

ENH/DEP add class method and deprecate plot function for confusion matrix #18543

Merged
merged 37 commits into from Jan 22, 2021

Conversation

@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Oct 6, 2020

Reference Issues/PRs

Addess some of #15880

What does this implement/fix? Explain your changes.

Introduce 2 class methods for ConfusionMatrixDisplay and deprecate the plot_ function.

This is the first of many successive PR. It is introducing the Substitution class to inject recurrent docstring and avoid duplicating code.

Any other comments?

@glemaitre glemaitre marked this pull request as draft Oct 6, 2020
@thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented Oct 6, 2020

@glemaitre While working on this PR, do you think that from_est and from_preds would be better because it it shorter? The whole *Display is already pretty verbose.

@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Oct 6, 2020

@glemaitre While working on this PR, do you think that from_est and from_preds would be better because it it shorter? The whole *Display is already pretty verbose.

To be honest, I prefer the long version especially for from_estimator. I find it more explicit. One can always rename the *Display at the import with as I think.

@glemaitre glemaitre marked this pull request as ready for review Oct 6, 2020
@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Oct 6, 2020

@thomasjpfan I think this is ready for being reviewed. Note that here, I did not change the visualization guideline. I think it would be best to change it at the same time as the ROC AUC display.

Here I am introducing a new utility to make docstring substitution as in matplotlib to avoid rewriting a long list of parameters. I can still revert it if it is considered as not needed. Otherwise, we might use it in other places.

@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Oct 6, 2020

@NicolasHug @thomasjpfan @ogrisel @amueller @jnothman

We can iterate on this PR such that it gets through and it will make the other PR easier to review then.

Copy link
Member

@NicolasHug NicolasHug left a comment

Thanks @glemaitre , a few minor comments but this looks good! thanks for working on this

To be honest, I prefer the long version

I agree

doc/whats_new/v0.24.rst Outdated Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/utils/tests/test_docstring.py Outdated Show resolved Hide resolved
sklearn/utils/_docstring.py Outdated Show resolved Hide resolved
@@ -0,0 +1,328 @@
from numpy.testing import (
Copy link
Member

@NicolasHug NicolasHug Oct 6, 2020

Choose a reason for hiding this comment

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

This is the same as the previous test file, with some minor adjustements, right?

Should we also test that both class methods yield the same plots? Maybe checking the confusion_matrix attribute is enough

Copy link
Contributor Author

@glemaitre glemaitre Oct 6, 2020

Choose a reason for hiding this comment

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

Yes, it is the same file but I used a fixture to test both constructor. Since some of the tests already compare to the confusion_matrix function output, I don't think that we need to check further.

sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/utils/_docstring.py Outdated Show resolved Hide resolved
Copy link
Member

@NicolasHug NicolasHug left a comment

Thanks @glemaitre , some grumpy morning comments but LGTM anyway!

@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Oct 7, 2020

@NicolasHug @thomasjpfan I removed the super meta-fixture :)
I agree it makes the test easier to understand and more explicit.

@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Oct 17, 2020

@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Oct 19, 2020

@adrinjalali Do you think that we can go forward?

Copy link
Member

@adrinjalali adrinjalali left a comment

Thanks, I'm happy with the docstrings as they are now :)

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Minor comment on tests, otherwise LGTM

sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
glemaitre and others added 2 commits Nov 3, 2020
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
doc/whats_new/v0.24.rst Outdated Show resolved Hide resolved
@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Jan 19, 2021

ping @adrinjalali Would it be fine to go ahead.

Copy link
Member

@adrinjalali adrinjalali left a comment

Thanks @glemaitre . I haven't checked the actual plots, otherwise looks pretty good :)

sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Outdated Show resolved Hide resolved
sklearn/metrics/_plot/confusion_matrix.py Show resolved Hide resolved
sklearn/metrics/_plot/tests/test_plot_confusion_matrix.py Outdated Show resolved Hide resolved
glemaitre and others added 2 commits Jan 20, 2021
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Base automatically changed from master to main Jan 22, 2021
@glemaitre glemaitre merged commit 8c6a045 into scikit-learn:main Jan 22, 2021
27 checks passed
@glemaitre
Copy link
Contributor Author

@glemaitre glemaitre commented Jan 22, 2021

Merging since the CIs are green and there is 2 approvals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants