【发布时间】:2015-07-06 15:26:26
【问题描述】:
这是我第一次使用 scikit learn metrics,我想使用这个库绘制 roc 曲线。
这条 ROC 曲线表明 AUC=1.00,我知道这是不正确的。代码如下:
from sklearn.metrics import roc_curve, auc
import pylab as pl
def show_roc(test_target, predicted_probs):
# set number 1
actual = [1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1]
prediction_probas = [0.374, 0.145, 0.263, 0.129, 0.215, 0.538, 0.24, 0.183, 0.402, 0.2, 0.281,
0.277, 0.222, 0.204, 0.193, 0.171, 0.401, 0.204, 0.213, 0.182]
fpr, tpr, thresholds = roc_curve(actual, prediction_probas)
roc_auc = auc(fpr, tpr)
# Plot ROC curve
pl.clf()
pl.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)
pl.plot([0, 1], [0, 1], 'k--')
pl.xlim([-0.1, 1.2])
pl.ylim([-0.1, 1.2])
pl.xlabel('False Positive Rate')
pl.ylabel('True Positive Rate')
pl.title('Receiver operating characteristic example')
pl.legend(loc="lower right")
pl.show()
对于这第一组,这是图表: http://i.stack.imgur.com/pa93c.png
概率非常低,尤其是正面,我不知道为什么它会为这些输入显示完美的 ROC 图。
# set number 2
actual = [1,1,1,0,0,0]
prediction_probas = [0.9,0.9,0.1,0.1,0.1,0.1]
fpr, tpr, thresholds = roc_curve(actual, prediction_probas)
roc_auc = auc(fpr, tpr)
# Plot ROC curve
pl.clf()
pl.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)
pl.plot([0, 1], [0, 1], 'k--')
pl.xlim([-0.1, 1.2])
pl.ylim([-0.1, 1.2])
pl.xlabel('False Positive Rate')
pl.ylabel('True Positive Rate')
pl.title('Receiver operating characteristic example')
pl.legend(loc="lower right")
pl.show()
这里的第二组是图形输出:
这个好像比较合理,我把它加进去比较一下。
我几乎一整天都在阅读 scikit learn 文档,但我很难过。
【问题讨论】:
标签: python scikit-learn roc