栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

roc_auc_score()和auc()的结果不同

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

roc_auc_score()和auc()的结果不同

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))


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/633914.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号