sparse_categorical_crossentropy 和 categorical_crossentropy 有什么区别? [英] What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?

查看:62
本文介绍了sparse_categorical_crossentropy 和 categorical_crossentropy 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sparse_categorical_crossentropycategorical_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) produces a one-hot array containing the probable match for each category,
  • sparse_categorical_crossentropy (scce) produces a category index of the most likely matching category.

考虑一个有 5 个类别(或类)的分类问题.

Consider a classification problem with 5 categories (or classes).

  • cce的情况下,one-hot target可能是[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 的情况下,one-hot 目标可能是 [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]

许多分类模型产生 scce 输出是因为您节省了空间,但会丢失很多信息(例如,在第二个示例中,索引 2 也非常接近.)我通常更喜欢 cce 输出模型可靠性.

Many categorical models produce scce output because you save space, but lose A LOT of information (for example, in the 2nd example, index 2 was also very close.) I generally prefer cce output for model reliability.

scce有多种使用情况,包括:

There are a number of situations to use scce, including:

  • 当您的类是相互排斥的,即您根本不关心其他足够接近的预测时,
  • 类别数量过多导致预测输出变得不堪重负.

这篇关于sparse_categorical_crossentropy 和 categorical_crossentropy 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆