You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggestion: Remove prediction from plot_confusion_matrix and just pass predicted labels #15880
The function takes an estimator and raw data and can not be used with already predicted labels. This has some downsides:
If a confusion matrix should be plotted but the predictions should also be used elsewhere (e.g. calculating accuracy_score) the estimation has to be performed several times. That takes longer and can result in different values if the estimator is randomized.
If no estimator is available (e.g. predictions loaded from a file) the plot can not be used at all.
Suggestion: allow passing predicted labels y_pred to plot_confusion_matrix that will be used instead of estimator and X. In my opinion the cleanest solution would be to remove the prediction step from the function and use a signature similar to that of accuracy_score, e.g. (y_true, y_pred, labels=None, sample_weight=None, ...). However in order to maintain backwards compatibility, y_pred can be added as an optional keyword argument.
TODO:
Introduce the class methods for the currently existing plots:
PartialDependenceDisplay. For this one, we don't want to introduce the from_predictions classmethod because it would not make sense, we only want from_estimator.
For all Display listed above, deprecate their corresponding plot_... function. We don't need to deprecate plot_det_curve because it hasn't been released yet, we can just remove it.
We should definitely stay backward compatible, but adding a y_pred keyword arg sounds reasonable to me. We should raise an error if y_pred is passed but X or estimator are also passed.
I agree that we should support plot_XXX(y_true, y_pred) to avoid calculating the prediction for multiple times.
We also have similar issues in plot_roc_curve and plot_precision_recall_curve.
Adding y_pred seems acceptable, but honestly I don't think it's a good solution.
For those functions which accept **kwargs (e.g., plot_precision_recall_curve), seems that it's impossible to keep backward compatible?
Hmm, so there's another annoying thing, we support **kwargs in plot_roc_curve and plot_precision_recall_curve (and plot_partial_dependence), but we do not support it in plot_confusion_matrix
The changes in my PR are backwards compatible and **kwargs can still be added. But I agree with @qinhanmin2014, a much much cleaner solution would be to throw out estimator and X and use positional arguments (y_true, y_pred, ...) that are consistent with most of the other sklearn stuff.
Looks like there's no strong opposition to using 2 class methods, so let's do that. We'll need to:
Introduce the class methods for the currently existing plots:
ConfusionMatrixDisplay
PrecisionRecallDisplay
RocCurveDisplay
DetCurveDisplay
PartialDependenceDisplay. For this one, we don't want to introduce the from_predictions classmethod because it would not make sense, we only want from_estimator.
For all Display listed above, deprecate their corresponding plot_... function. We don't need to deprecate plot_det_curve because it hasn't been released yet, we can just remove it.
I will take care of the other classes then and advance my stalled PR. @lucyleeow in case I did not do all of those and you are searching for some PRs, ping me :)
Activity
NicolasHug commentedon Dec 13, 2019
We should definitely stay backward compatible, but adding a
y_predkeyword arg sounds reasonable to me. We should raise an error if y_pred is passed but X or estimator are also passed.Would you want to submit a PR @jhennrich ?
jhennrich commentedon Dec 13, 2019
I submitted a PR, but I think there is currently a problem with the CI so it has not passed yet.
qinhanmin2014 commentedon Dec 13, 2019
I agree that we should support
plot_XXX(y_true, y_pred)to avoid calculating the prediction for multiple times.We also have similar issues in plot_roc_curve and plot_precision_recall_curve.
Adding y_pred seems acceptable, but honestly I don't think it's a good solution.
For those functions which accept **kwargs (e.g., plot_precision_recall_curve), seems that it's impossible to keep backward compatible?
NicolasHug commentedon Dec 13, 2019
Why is it impossible to keep the backward compatibility? It seems to me that the proposal in #15883 is OK
qinhanmin2014 commentedon Dec 13, 2019
because we do not support **kwargs in plot_confusion_matrix. @NicolasHug
NicolasHug commentedon Dec 13, 2019
Why is kwargs a problem?
qinhanmin2014 commentedon Dec 13, 2019
Hmm, so there's another annoying thing, we support **kwargs in plot_roc_curve and plot_precision_recall_curve (and plot_partial_dependence), but we do not support it in plot_confusion_matrix
qinhanmin2014 commentedon Dec 13, 2019
if we add the new parameter before **kwargs, we can keep backward compatibility, right?
jhennrich commentedon Dec 13, 2019
The changes in my PR are backwards compatible and **kwargs can still be added. But I agree with @qinhanmin2014, a much much cleaner solution would be to throw out
estimatorandXand use positional arguments (y_true, y_pred, ...) that are consistent with most of the other sklearn stuff.NicolasHug commentedon Dec 13, 2019
yes
Unfortunately that would require a deprecation cycle (unless we make it very fast in the bugfix release but I doubt it...)
@thomasjpfan , any reason to pass the estimator as input instead of the predictions?
qinhanmin2014 commentedon Dec 13, 2019
Thanks, let's add y_pred first, **kwags is another issue.
qinhanmin2014 commentedon Dec 13, 2019
This seems impossible, sigh
I agree that we need to reconsider our API design. also try to ping @amueller
51 remaining items
NicolasHug commentedon Oct 3, 2020
Looks like there's no strong opposition to using 2 class methods, so let's do that. We'll need to:
Introduce the class methods for the currently existing plots:
ConfusionMatrixDisplayPrecisionRecallDisplayRocCurveDisplayDetCurveDisplayPartialDependenceDisplay. For this one, we don't want to introduce thefrom_predictionsclassmethod because it would not make sense, we only wantfrom_estimator.For all Display listed above, deprecate their corresponding
plot_...function. We don't need to deprecateplot_det_curvebecause it hasn't been released yet, we can just remove it.for new PRs like ENH Add CalibrationDisplay plotting class #17443 and FEA add PredictionErrorDisplay #18020 we can implement the class methods right away instead of introducing a
plotfunction.This is a bit of work but I think we can get this done before 0.24 so that #17443 and #18020 can move forward already.
Any objection @thomasjpfan @jnothman @amueller @glemaitre ?
@jhennrich @pzelasko , would you be interested in submitting a PR to introduce the class methods in one of the Display objects?
lucyleeow commentedon Oct 3, 2020
Thanks for making the decision @NicolasHug! I'll get onto #17443 (after waiting for objections)
thomasjpfan commentedon Oct 5, 2020
I have no objections.
glemaitre commentedon Oct 6, 2020
No objection as well.
glemaitre commentedon Oct 6, 2020
I will take care of the other classes then and advance my stalled PR.
@lucyleeow in case I did not do all of those and you are searching for some PRs, ping me :)
pzelasko commentedon Oct 6, 2020
I'd love to contribute but I'm engaged in too many projects at this time. Thanks for listening to the suggestions!
amueller commentedon Oct 7, 2020
Sounds good :)
adrinjalali commentedon Aug 22, 2021
Seems like there's been good progress here. Removing the milestone, but pinging y'all in case you think something needs to get in before the release.
glemaitre commentedon Aug 22, 2021
thomasjpfan commentedon Apr 15, 2022
I am closing this issue because all the tasks in the original issue has been merged.