【发布时间】:2016-12-26 22:45:06
【问题描述】:
问题
我正在尝试使用 scikit-learn 的 LogisticRegressionCV 和 roc_auc_score 作为评分指标。
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
clf = LogisticRegressionCV(scoring=roc_auc_score)
但是当我尝试拟合模型 (clf.fit(X, y)) 时,它会引发错误。
ValueError: average has to be one of (None, 'micro', 'macro', 'weighted', 'samples')
这很酷。很清楚发生了什么:roc_auc_score 需要使用指定的average 参数调用,根据its documentation 和上面的错误。所以我尝试了。
clf = LogisticRegressionCV(scoring=roc_auc_score(average='weighted'))
但事实证明,roc_auc_score 不能单独使用可选参数调用,因为这会引发另一个错误。
TypeError: roc_auc_score() takes at least 2 arguments (1 given)
问题
对于如何使用roc_auc_score 作为LogisticRegressionCV 的评分指标有什么想法,我可以为评分函数指定一个参数?
我在 scikit-learn 的 GitHub 存储库中找不到关于此问题的 SO 问题或对此问题的讨论,但肯定有人以前遇到过这个问题吗?
【问题讨论】:
-
根据您链接到
average的文档,默认值为“macro”,因此不应导致错误。 -
是的,不知道为什么它要求定义该论点。我认为这可能是我正在使用的版本 (
0.16.1),但该版本的文档显示相同的内容。
标签: python function arguments scikit-learn scoring