AUC 并不总是 ROC 曲线下的面积。曲线下面积是some曲线下的(抽象)面积,所以它比AUROC更笼统。对于不平衡的类,找到精确召回曲线的 AUC 可能会更好。
查看roc_auc_score的sklearn源代码:
def roc_auc_score(y_true, y_score, average="macro", sample_weight=None):
# <...> docstring <...>
def _binary_roc_auc_score(y_true, y_score, sample_weight=None):
# <...> bla-bla <...>
fpr, tpr, tresholds = roc_curve(y_true, y_score,
sample_weight=sample_weight)
return auc(fpr, tpr, reorder=True)
return _average_binary_score(
_binary_roc_auc_score, y_true, y_score, average,
sample_weight=sample_weight)
如你所见,这首先得到一个roc曲线,然后调用auc()得到面积。
我猜你的问题是predict_proba() 电话。对于普通的predict(),输出总是相同的:
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve, auc, roc_auc_score
est = LogisticRegression(class_weight='auto')
X = np.random.rand(10, 2)
y = np.random.randint(2, size=10)
est.fit(X, y)
false_positive_rate, true_positive_rate, thresholds = roc_curve(y, est.predict(X))
print auc(false_positive_rate, true_positive_rate)
# 0.857142857143
print roc_auc_score(y, est.predict(X))
# 0.857142857143
如果您为此更改上述内容,有时会得到不同的输出:
false_positive_rate, true_positive_rate, thresholds = roc_curve(y, est.predict_proba(X)[:,1])
# may differ
print auc(false_positive_rate, true_positive_rate)
print roc_auc_score(y, est.predict(X))