python - 如何在gridsearchcv中使用log_loss记分器?

标签 python machine-learning scikit-learn grid-search

是否可以在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/

相关文章:

python - Selenium ( python ): How to execute methods in order

apache-spark - Spark 和 Spark Streaming 中的时间序列预测

Python 3.5 装饰器和函数域

python - keras 编码器和解码器上的分割自动编码器

machine-learning - 使用 mcl 可以使用哪些参数?

python - Scikit-learn:如何在一维数组上运行 KMeans?

image-processing - 图像中的 XY 坐标存储为 numpy?

Scikit-Learn:timeseriessplit 中的测试大小

python - Python 类中的池

python - 弧形中的不同颜色