tf.keras.losses.Huber 损失函数 示例

Huber损失,平滑的平均绝对误差
Huber损失对数据中的异常点没有平方误差损失那么敏感。
本质上,Huber损失是绝对误差,只是在误差很小时,就变为平方误差。误差降到多小时变为二次误差由超参数δ(delta)来控制。当Huber损失在[0-δ,0+δ]之间时,等价为MSE,而在[-∞,δ]和[δ,+∞]时为MAE。

loss = 0.5 * x^2 if |x| <= d
loss = 0.5 * d^2 + d * (|x| - d) if |x| > d

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s7Tpl5cD-1637722172450)(C:\Users\xiahuadong\Documents\csdn博客\huber损失函数公式1.png)]

import tensorflow as tf
y_true = [[0, 1], [0, 0]]
y_pred = [[0.6, 0.4], [0.4, 0.6]]
# Using 'auto'/'sum_over_batch_size' reduction type.
h = tf.keras.losses.Huber()
h(y_true, y_pred).numpy()
0.155

猜你喜欢

转载自blog.csdn.net/weixin_44493841/article/details/121510638