Welcome to our Support Center



Computes the hinge metric between y_true and y_pred. Type : polymorphic.



Input parameters


Β y_pred : array,Β predicted values.
Β y_true : array,Β true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we will convert them to -1 or 1.


Output parameters


hinge : float, result.

Use cases

The hinge loss function, also known as margin loss, is a metric used in machine learning, in particular for binary classification problems such as Support Vector Machines (SVM). The hinge loss measures the distance between each data point and the decision frontier, aiming to maximize this distance to better separate classes. This metric is called “margin” loss because it seeks to maximize the margin between classes in the feature space.

It is particularly used in areas where SVMs have traditionally been employed, such as :

  • Image recognition : for example, identifying whether an image contains a cat or a dog.
  • Spam detection : for example, determining whether an email is spam or not.
  • Bioinformatics : for example, classifying genetic sequences.

It should be noted that although SVMs are often associated with hinge loss, this loss function can also be used with other types of machine learning models.


The principle of the Hinge metric is to maximise the margin between positive and negative examples. If the prediction is correct and the margin is greater than 1, the loss is 0. If the prediction is incorrect, or if the margin is less than 1, even if the prediction is correct, the loss is calculated as a function of the difference from 1.

So not only does it penalise incorrect classifications, but also correct classifications that are not sufficiently confident. The idea is to encourage the model to make more confident predictions, while minimising errors.



All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install HAIBAL library to run it).

Easy to use

Table of Contents