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

平方铰链

l o s s = ( M a x ( 1 − 正 确 值 × 预 测 值 , 0 ) ) 2 loss=(Max(1-正确值\times 预测值,0))^{2} loss=(Max(1×,0))2

正确值应为 -1 或 1。如果提供了二进制(0 或 1)标签,我们会将其转换为 -1 或 1

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.SquaredHinge()
h(y_true, y_pred).numpy()
1.86

猜你喜欢

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