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
[MRG] Allow plot_confusion_matrix to be called on predicted labels #15883
[MRG] Allow plot_confusion_matrix to be called on predicted labels #15883
Conversation
…of an estimator and features.
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.
Thanks for the PR @jhennrich
Don't worry about CI failing for now, it's unrelated.
please add a few tests. We would also need a short sentence in the user guide (doc/modules/model_evaluation.rst) to document this feature
thanks, please apply similar changes to plot_roc_curve and plot_precision_recall_curve |
Maybe we can make changes to the other functions in another PR |
@NicolasHug: I fixed everything you suggested and added tests. |
Hi, what happened with this? it seems ready to be merged. What are the plans for ROC curve and others? I feel quite inefficient having to predict again if I want to plot the ROC curve On a similar matter, what do you think in general about having just one function with a boolean to plot? wouldn't that simplify a lot the API?
I think this would be nice because maybe you want to plot the CM, ROC, etc, and also have it. For example, you wanna plot the ROC curve and choose the threshold |
@marctorrellas There is a discussion on #15880 going through if we want inflate the API of this function. In summary, having two interfaces in one function feels like it will lead to an inflated API. The way to do this with already computed predictions would be to: from sklearn.metrics import ConfusionMatrixDisplay
y_pred = est.predict(...)
confusion_matrix = confusion_matrix(y_true, y_pred)
display_labels = [...]
disp = ConfusionMatrixDisplay(confusion_matrix=confusion_matrix,
display_labels=display_labels).plot(...) |
thanks so much for your answer! didn't realise about those *****Display 👍 |
Now that ConfusionMatrix.from_predictions is released, we can now plot the confusion matrix from the predictions directly. With that in mind, I am closing this PR. Thank you for working on this PR! |
Allow passing predicted labels
y_pred
toplot_confusion_matrix
that will be used instead ofestimator
andX
. In order to maintain backwards compatibility,y_pred
is added as an optional keyword argument.When both
estimator
andX
aswell asy_pred
are passed, a ValueError is raised since it is unclear which of both should be used.For the discussion see #15880