Home > Net >  Can you plot multiple precision-recall curves using PrecisionRecallDisplay?
Can you plot multiple precision-recall curves using PrecisionRecallDisplay?

Time:10-12

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?

CodePudding user response:

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()
  • Related