您可以使用 PrecisionRecallDisplay 绘制多条精确召回曲线吗?

Kar*_*oos 4 python machine-learning scikit-learn precision-recall

我正在尝试使用 scikit-learn 中的PrecisionRecallDisplay绘制 Precision Recall 曲线。

我有模型预测值y_pred和实际值y_true。我可以使用以下语法绘制精确召回曲线:

metrics.PrecisionRecallDisplay.from_predictions(y_true, y_pred)
Run Code Online (Sandbox Code Playgroud)

但我想在同一个图中绘制多条曲线(例如通过在训练或验证数据上应用模型)。

那么可以使用 来实现这一点吗 PrecisionRecallDisplay?或者是否有其他标准方法可以使用 scikit-learn 来实现此目的?

dx2*_*-66 9

由于 sklearn 显示例程基本上只是 matplotlib 包装器,因此最简单的方法似乎是利用ax参数,如下所示:

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()
Run Code Online (Sandbox Code Playgroud)