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

import tensorflow as tf 

铰链损失函数

它可用于“最大间隔(max-margin)”分类,其最著名的应用是作为SVM的损失函数。

二分类

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

多分类

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

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

猜你喜欢

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