引用维基百科:
The ROC is created by plotting the FPR (false positive rate) vs the TPR (true positive rate) at various thresholds settings.
为了计算FPR和TPR,您必须将正二进制值和目标分数提供给函数sklearn.metrics.roc_curve.
所以在你的情况下,我会做这样的事情:
from sklearn.metrics import roc_curve
from sklearn.metrics import auc
# Compute fpr,tpr,thresholds and roc auc
fpr,thresholds = roc_curve(y_true,y_score)
roc_auc = auc(y_true,y_score)
# Plot ROC curve
plt.plot(fpr,label='ROC curve (area = %0.3f)' % roc_auc)
plt.plot([0,1],[0,'k--') # random predictions curve
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.0])
plt.xlabel('False Positive Rate or (1 - Specifity)')
plt.ylabel('True Positive Rate or (Sensitivity)')
plt.title('Receiver Operating Characteristic')
plt.legend(loc="lower right")
如果您想更深入地了解如何计算所有可能的阈值的假阳性率和真阳性率,我建议您阅读this article