常用loss:
L1:
- 公式:L1=i=1∑n∣yi−f(xi)∣
- 导数:dxdL1(x)={1−1 if x≥0 otherwise
L2:
- 公式:L2=i=1∑n(yi−f(xi))2
- 导数:dxdL2(x)=2x
- 特性:对离群点比较敏感,需要自习调整学习率,防止出现梯度爆炸的情况(因为两端值很大);
smooth L1:
- 公式:smoothL1(x)={0.5x2∣x∣−0.5 if ∣x∣<1 otherwise
- 导数:dxdsmoothL1={x±1 if ∣x∣<1 otherwise
Huber loss:
- 公式:Lδ(y,f(x))={21(y−f(x))2,δ⋅(∣y−f(x)∣−21δ), for ∣y−f(x)∣≤δ otherwise
- 优点是能增强平方误差损失函数(MSE)对离群点的鲁棒性,用于回归问题。δ是一个可以自己设置的参数。
当预测偏差小于 δ 时,它采用平方误差,
当预测偏差大于 δ 时,采用的线性误差。
[外链图片转存失败(img-TExue3Iw-1568215766580)(./1567858938658.png)]
如上图绿色部分为huber loss。
[外链图片转存失败(img-kAJeSxmv-1568215766580)(./1567846985700.png)]
说明
L1loss在零点不平滑,学习慢;
L2loss学习快,因为是平方增长,但是当预测值太大的时候,会在loss中占据主导位置(如真实值为1,预测多次,有一次预测值为100,其余预测为2);
Smooth L1 Loss 相比L1修改零点不平滑问题,而且在x较大的时候不像L2对异常值敏感,是一个缓慢变化的loss;
Huber loss增强L2对离群点的鲁棒性,因为偏差大的时候变成线性增长;
上图绿色部分为huber loss,紫色部分为L2loss;
上图为smooth L1 loss和L2 loss的导数对比,在两端smooth L1 导数恒定为1,而L2 loss会一直上升;
另外L1和L2范数常用于正则化项:
L1正则会制造稀疏的特征,大部分无用特征的权重会被置为0,有特征选择作用;
L2正则会让特征的权重不过大,使得特征的权重比较平均。
上图为1范数和2范数的图像,可以看出L1正则倾向于选择坐标轴上的参数(即出现0为稀疏解),L2正则倾向于选择均匀参数;