我在用sklearn的logu loss
from sklearn.metrics import log_loss
print log_loss(true, pred,normalize=False)
我有以下错误:
ValueError: y_true and y_pred have different number of classes 38, 2
我真的很奇怪,因为数组看起来是有效的:
print pred.shape
print np.unique(pred)
print np.unique(pred).size
(19191L,)
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37]
38
print true.shape
print np.unique(true)
print np.unique(true).size
(19191L,)
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37]
38
原木丢失怎么了?为什么会抛出错误?
样本数据:
pred: array([ 0, 1, 2, ..., 3, 12, 16], dtype=int64)
true: array([ 0, 1, 2, ..., 3, 12, 16])
从日志损失文档中:
你需要传递概率而不是预测标签。
很简单,你用的是预测,而不是预测的概率。pred变量包含
但是要使用日志损失它应该包含如下内容:
要获得这些概率,请使用函数
predict_proba
:在log_loss方法中,真正的数组由一个LabelBinarizer进行拟合和变换,该LabelBinarizer改变了数组的维数。因此,检查true和pred具有相似的维度并不意味着log_loss方法会工作,因为true的维度发生了变化。如果您只是有二进制类,我建议您使用这个log_loss cost函数,否则对于多个类,这个方法不起作用。
相关问题 更多 >
编程相关推荐