平方铰链
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