是否可以在gridsearchcv中使用log_loss指标?
我见过很少有人提到 neg_log_loss
的帖子?它与log_loss
相同吗?如果没有可以直接在gridsearchcv中使用log_loss吗?
最佳答案
如 documentation 中所述,评分可能采用不同的输入:字符串、可调用、列表/元组、字典或无。如果您使用字符串,您可以找到可能条目的列表 here 。
在那里,作为代表对数损失的字符串,您可以找到“neg_log_loss”,即负对数损失,它只是对数损失乘以-1。这是处理最大化问题(这正是 GridSearchCV 所期望的,因为它需要分数参数,而不是损失参数)的简单方法,而不是最小化问题(您想要最小对数损失,这相当于最大损失参数)负对数损失)。
如果您想直接将对数损失函数传递给 GridSearchCV,则只需从 Scikit-learn log_loss 创建一个记分器即可使用 make_scorer 函数:
from sklearn import svm, datasets
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import log_loss, make_scorer
iris = datasets.load_iris()
parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
svc = svm.SVC(gamma="scale", probability=True)
LogLoss = make_scorer(log_loss, greater_is_better=False, needs_proba=True)
clf = GridSearchCV(svc, parameters, cv=5, scoring=LogLoss)
clf.fit(iris.data, iris.target)
print(clf.best_score_, clf.best_estimator_)
关于python - 如何在gridsearchcv中使用log_loss记分器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55892224/