各种 loss 的了解 (binary/categorical crossentropy)

损失函数是机器学习最重要的概念之一。通过计算损失函数的大小,是学习过程中的主要依据也是学习后判断算法优劣的重要判据。

1.binary_crossentropy交叉熵损失函数,一般用于二分类:

                                       

这个是针对概率之间的损失函数,你会发现只有yi和ŷ i是相等时,loss才为0,否则loss就是为一个正数。而且,概率相差越大,loss就越大。这个神奇的度量概率距离的方式称为交叉熵。

 

2.categorical_crossentropy分类交叉熵函数:

=====================================================================================================

作者:Yohanna
链接:https://www.zhihu.com/question/36307214/answer/364963552
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
 

交叉熵损失函数:

交叉熵可在神经网络(机器学习)中作为损失函数。 如下公式所示:y表示真实标记的分布,a则为训练后的模型的预测标记分布,交叉熵损失函数可以衡量y与a的相似性。交叉熵作为损失函数还有一个好处是使用sigmoid函数在梯度下降时能避免均方误差损失函数学习速率降低的问题,因为学习速率可以被输出的误差所控制。

  1. Binary Cross Entropy

常用于二分类问题,当然也可以用于多分类问题,通常需要在网络的最后一层添加sigmoid进行配合使用,其期望输出值(target)需要进行one hot编码,另外BCELoss还可以用于多分类问题Multi-label classification.

定义:
For brevity, let x = output, z = target. The binary cross entropy loss is
loss(x, z) = - sum_i (x[i] * log(z[i]) + (1 - x[i]) * log(1 - z[i]))

对应的代码为:

def binary_crossentropy(t,o):
    return -(t*tf.log(o+eps) + (1.0-t)*tf.log(1.0-o+eps))

2. Categorical cross-entropy

 

p are the predictions, t are the targets, i denotes the data point and j denotes the class.

适用于多分类问题,并使用softmax作为输出层的激活函数的情况。

This is the loss function of choice for multi-class classification problems and softmax output units. For hard targets, i.e., targets that assign all of the probability to a single class per data point, providing a vector of int for the targets is usually slightly more efficient than providing a matrix with a single 1.0 per row.

References:

[1] Neural Networks, Manifolds, and Topology

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值