我想绘制我的精度/召回曲线的阈值。我只是使用MNSIT数据,来自书籍《scikit-learn、keras和TensorFlow实战》中的示例。尝试训练模型以检测数字5的图像。我不知道您需要看多少代码。我已经为训练集制作了混淆矩阵,并计算了精确度和召回率值,以及阈值。我已经绘制了预测/召回曲线,但是书中的示例说要添加轴标签、图例、网格并突出显示阈值,但是代码在我放置下面的星号处截断了。我已经能够解决所有问题,除了如何在图中显示阈值。我已经包含了一张书上的图形与我所拥有的图形进行比较。这是书上的图像:
,而这是我的图形:
![enter image description here](https://istack.dev59.com/MuRHQ.webp)
我无法让具有两个阈值点的红色虚线显示出来。有人知道我该如何做吗?以下是我的代码:
from sklearn.metrics import precision_recall_curve
precisions, recalls, thresholds = precision_recall_curve(y_train_5, y_scores)
def plot_precision_recall_vs_thresholds(precisions, recalls, thresholds):
plt.plot(thresholds, precisions[:-1], "b--", label="Precision")
plt.plot(thresholds, recalls[:-1], "g--", label="Recall")
plt.xlabel("Threshold")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
plt.grid(b=True, which="both", axis="both", color='gray', linestyle='-', linewidth=1)
plot_precision_recall_vs_thresholds(precisions, recalls, thresholds)
plt.show()
我知道这里有很多关于使用sklearn的问题,但似乎没有涉及如何显示那条红线。非常感谢您的帮助!