【发布时间】:2018-07-08 08:44:29
【问题描述】:
以下代码
from sklearn import metrics
import numpy as np
y_true = np.array([[0.2,0.8,0],[0.9,0.05,0.05]])
y_predict = np.array([[0.5,0.5,0.0],[0.5,0.4,0.1]])
metrics.log_loss(y_true, y_predict)
产生以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-32-24beeb19448b> in <module>()
----> 1 metrics.log_loss(y_true, y_predict)
~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\sklearn\metrics\classification.py in log_loss(y_true, y_pred, eps, normalize, sample_weight, labels)
1646 lb.fit(labels)
1647 else:
-> 1648 lb.fit(y_true)
1649
1650 if len(lb.classes_) == 1:
~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\sklearn\preprocessing\label.py in fit(self, y)
276 self.y_type_ = type_of_target(y)
277 if 'multioutput' in self.y_type_:
--> 278 raise ValueError("Multioutput target data is not supported with "
279 "label binarization")
280 if _num_samples(y) == 0:
ValueError: Multioutput target data is not supported with label binarization
我很好奇为什么。我正在尝试重新阅读日志丢失的定义,但找不到任何会使计算不正确的内容。
【问题讨论】:
-
在 scikit 中,log_loss 仅针对分类任务定义,如下所述:- scikit-learn.org/stable/modules/…
-
@VivekKumar,谢谢Vivek,你的意思是说二元分类任务?我说的问题仍然是分类,而不是二元。
-
我已经添加了我对您问题的解释作为答案。请仔细阅读并告诉您是否需要。
标签: python scikit-learn cross-entropy