我使用sklearn
precision_recall_curve
函数和matplotlib
包绘制了精确召回曲线。对于熟悉精确召回曲线的人来说,您知道一些科学界仅在其插值时才接受它,类似于此处的示例。现在我的问题是你们中是否有人知道如何在 python 中进行插值?我一直在寻找解决方案一段时间,但没有成功!任何帮助将不胜感激。
解决方案: @francis 和 @ali_m 的两个解决方案都是正确的,共同解决了我的问题。因此,假设您从 in 中的precision_recall_curve
函数获得输出sklearn
,这就是我绘制图表时所做的:
precision["micro"], recall["micro"], _ = precision_recall_curve(y_test.ravel(),scores.ravel())
pr = copy.deepcopy(precision[0])
rec = copy.deepcopy(recall[0])
prInv = np.fliplr([pr])[0]
recInv = np.fliplr([rec])[0]
j = rec.shape[0]-2
while j>=0:
if prInv[j+1]>prInv[j]:
prInv[j]=prInv[j+1]
j=j-1
decreasing_max_precision = np.maximum.accumulate(prInv[::-1])[::-1]
plt.plot(recInv, decreasing_max_precision, marker= markers[mcounter], label=methodNames[countOfMethods]+': AUC={0:0.2f}'.format(average_precision[0]))
如果您将这些线放在 for 循环中并在每次迭代时将每个方法的数据传递给它,这些线将绘制插值曲线。请注意,这不会绘制非插值精度召回曲线。