Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you plot multiple precision-recall curves using PrecisionRecallDisplay?

I am trying to plot Precision Recall curve using PrecisionRecallDisplay from scikit-learn.

I have model predicted values in y_pred and actual values in y_true. I can plot precision recall curve using the following syntax:

metrics.PrecisionRecallDisplay.from_predictions(y_true, y_pred)

But I want to plot multiple curves (say by applying model on training or validation data) in the same plot.

So is it possible to achieve this using PrecisionRecallDisplay? Or Is there some other standard way to achieve this using scikit-learn?

like image 629
Kartoos Avatar asked Oct 26 '25 05:10

Kartoos


1 Answers

Since sklearn display routines are basically just matplotlib wrappers, the easiest way seems to be utilizing the ax argument, like this:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
PrecisionRecallDisplay.from_predictions(y_train, y_pred_train, ax=ax)
PrecisionRecallDisplay.from_predictions(y_test, y_pred, ax=ax)
plt.show()
like image 143
dx2-66 Avatar answered Oct 28 '25 19:10

dx2-66



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!