我有一个 Boosted Trees 模型,用于测试数据集的概率和分类。我试图为其绘制 ROC 曲线,但我无法确定如何在 Scikit-learn 中定义阈值/α 值。
from sklearn.metrics import precision_recall_curve,roc_curve,auc, average_precision_score
fpr = dict()
tpr = dict()
roc_auc = dict()
fpr,tpr,_ = roc_curve(ytest,p_test, pos_label=1)
roc_auc = auc(fpr,tpr)
plt.figure()
lw = 2
plt.plot(fpr, tpr, color='darkorange', lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.savefig('ROCProb.png')
plt.show()
我在这里看到了一个类似的问题:scikit-learn中roc_curve中的阈值
但是我无法弄清楚。我也可以使用其他库。
roc_curve
(在您的情况下是变量_)中返回。 - sgDysregulation