Understanding hinge loss
See original GitHub issueI am learning Tensorflow 2.X
. I am following this page to understand hinge loss.
I went through the standalone usage code.
Code is below -
y_true = [[0., 1.], [0., 0.]]
y_pred = [[0.6, 0.4], [0.4, 0.6]]
h = tf.keras.losses.Hinge()
h(y_true, y_pred).numpy()
the output is 1.3
I tried to manually calculate it by given formula
loss = maximum(1 - y_true * y_pred, 0)
my code -
def hinge_loss(y_true, y_pred):
return tf.reduce_mean(tf.math.maximum(1. - y_true * y_pred, 0.))
print("Hinge Loss :: ", hinge_loss(y_true, y_pred).numpy())
But I am getting 0.9
.
Where am i doing wrong ? Am i missing any concept here ?
Kindly guide.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
A definitive explanation to the Hinge Loss for Support Vector ...
One key characteristic of the SVM and the Hinge loss is that the boundary separates negative and positive instances as +1 and -1,...
Read more >Understanding loss functions : Hinge loss | by Kunal Chowdhury
From our SVM model, we know that hinge loss = [0, 1- yf(x)]. Looking at the graph for SVM in Fig 4, we...
Read more >Hinge loss - Wikipedia
In machine learning, the hinge loss is a loss function used for training classifiers. The hinge loss is used for "maximum-margin" classification, ...
Read more >Hinge Loss Explained with a Table Instead of a Graph
If a computed value gives a correct classification but is too close to zero (where too close is defined by a margin )...
Read more >What is the definition of the hinge loss function?
The hinge loss/error function is the typical loss function used for binary classification (but it can also be extended to multi-class ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, now i am able to replicate reported issue on Colab using TF v2.7. Please find the gist here for reference. Thanks!
@old-school-kid Got it. Thank you so much.