sparse_categorical_crossentropy和categorical_crossentropy有什么区别? [英] What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
问题描述
sparse_categorical_crossentropy
和 categorical_crossentropy
有什么区别?什么时候应该使用一种损失而不是另一种?例如,这些损失是否适合线性回归?
What is the difference between sparse_categorical_crossentropy
and categorical_crossentropy
? When should one loss be used as opposed to the other? For example, are these losses suitable for linear regression?
推荐答案
简单地:
-
categorical_crossentropy
(cce
)使用单热点数组来计算概率, -
sparse_categorical_crossentropy
(scce
)使用类别索引
categorical_crossentropy
(cce
) uses a one-hot array to calculate the probability,sparse_categorical_crossentropy
(scce
) uses a category index
考虑具有5个类别(或类)的分类问题。
Consider a classification problem with 5 categories (or classes).
-
在
cce
的情况下,一个热门目标可能是[0,1,0,0,0]
,该模型可能会预测[。2,.5,.1,.1,.1]
(可能正确)
In the case of
cce
, the one-hot target may be[0, 1, 0, 0, 0]
and the model may predict[.2, .5, .1, .1, .1]
(probably right)
在 scce
的情况下,目标索引可能为[1],并且模型可以预测为:[.5]。
In the case of scce
, the target index may be [1] and the model may predict: [.5].
现在考虑3类分类问题。
Consider now a classification problem with 3 classes.
- 对于
cce
,一个热门目标可能是[0,0,1]
,模型可以预测[。5,。 1,.4]
(可能不准确,因为它给头等舱带来了更多的可能性) - 对于
scce
,目标索引可能是[0]
,并且模型可能会预测[。5]
- In the case of
cce
, the one-hot target might be[0, 0, 1]
and the model may predict[.5, .1, .4]
(probably inaccurate, given that it gives more probability to the first class) - In the case of
scce
, the target index might be[0]
, and the model may predict[.5]
大多数分类模型会产生一次性熵和分类熵,因为您可以节省空间,但会丢失大量信息(例如,第二种情况,使用稀疏时索引2也非常接近。我总是使用一口气并研究 cce
输出的模型可靠性。
Most categorical models produce one-hot and categorical entropy because you save space, but lose A LOT of information (for example, in the 2nd case, index 2 was also very close) when using sparse. I always use one-hot and study the cce
output for model reliability.
简而言之,请使用 sparse_categorical_crossentropy
,如果您的类是互斥的,即您根本不在乎其他足够接近的预测。
In short, use sparse_categorical_crossentropy
when your classes are mutually exclusive, i.e. you don't care at all about other close enough predictions.
这篇关于sparse_categorical_crossentropy和categorical_crossentropy有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!