question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Understanding hinge loss

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
chundurivcommented, Nov 22, 2021

Yes, now i am able to replicate reported issue on Colab using TF v2.7. Please find the gist here for reference. Thanks!

0reactions
jay-thakurcommented, Dec 11, 2021

@old-school-kid Got it. Thank you so much.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found