AUC并不总是在ROC曲线的曲线下方。曲线下面积为下(抽象)地区 的一些
曲线,所以它比AUROC更一般的事情。对于不平衡的类,最好为精确调用曲线找到AUC。
请参阅sklearn来源
roc_auc_score:
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 npfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import roc_curve, auc, roc_auc_scoreest = 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.857142857143print 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 differprint auc(false_positive_rate, true_positive_rate)print roc_auc_score(y, est.predict(X))



