scikit-学习roc_auc_score()返回精度值 [英] scikit-learn roc_auc_score() returns accuracy values
问题描述
我正在尝试使用sklearn.metrics.roc_auc_score
使用以下方法来计算ROC曲线下的面积:
I am trying to compute area under the ROC curve using sklearn.metrics.roc_auc_score
using the following method:
roc_auc = sklearn.metrics.roc_auc_score(actual, predicted)
其中actual
是带有地面真实分类标签的二进制向量,而predicted
是带有我的分类器预测的分类标签的二进制向量.
where actual
is a binary vector with ground truth classification labels and predicted
is a binary vector with classification labels that my classifier has predicted.
但是,我得到的roc_auc
的值与准确度值(正确预测了标签的样本比例)完全相似.这不是一次性的事情.我会在各种参数值上尝试分类器,并且每次获得相同结果时都会如此.
However, the value of roc_auc
that I am getting is EXACTLY similar to accuracy values (proportion of samples whose labels are correctly predicted). This is not a one-off thing. I try my classifier on various values of the parameters and every time I get the same result.
我在做什么错了?
推荐答案
这是因为您正在传递分类器的决策,而不是其计算出的分数.最近在SO上对此问题有一个问题,并且对scikit-learn
的相关拉取请求.
This is because you are passing in the decisions of you classifier instead of the scores it calculated. There was a question on this on SO recently and a related pull request to scikit-learn
.
ROC曲线的点(及其下的区域)是您在分类阈值变化时研究精确调用折衷.默认情况下,在二进制分类任务中,如果分类器的得分为> 0.5
,则预测为class1
,否则为class0
.更改该阈值时,您会得到类似 this 的曲线.曲线越高(曲线下方的面积越大),分类器就越好.但是,要获得此曲线,您需要访问分类器的分数,而不是其决策.否则,无论决策阈值是多少,决策都将保持不变,并且AUC会退化为准确性.
The point of a ROC curve (and the area under it) is that you study the precision-recall tradeoff as the classification threshold is varied. By default in a binary classification task, if your classifier's score is > 0.5
, then class1
is predicted, otherwise class0
is predicted. As you change that threshold, you get a curve like this. The higher up the curve is (more area under it), the better that classifier. However, to get this curve you need access to the scores of a classifier, not its decisions. Otherwise whatever the decision threshold is, the decision stay the same, and AUC degenerates to accuracy.
您正在使用哪个分类器?
Which classifier are you using?
这篇关于scikit-学习roc_auc_score()返回精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!