ArticleslgStudy

mathematics

Hinge loss

Hinge loss is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Hinge loss rather than just read about it. In short: In machine learning, hinge loss is a loss function used for training classifiers. Hinge loss is used for "maximum-margin" classification, most notably for support vector machines (SVMs).

Hinge loss — main illustration
Hinge loss — illustration

Key takeaways

  • Hinge loss belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Hinge loss to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Hinge loss from memory before moving on to harder problems.

Reference excerpt

In machine learning, hinge loss is a loss function used for training classifiers. Hinge loss is used for "maximum-margin" classification, most notably for support vector machines (SVMs).

Definition For an intended output t = ±1 and a classifier score y, the hinge loss of the prediction y is defined as:

ℓ(y)=max⁡(0,1−t⋅y) Note that y should be the "raw" output of the classifier's decision function, not the predicted class label. For instance, in linear SVMs, y=𝐰⋅𝐱+b, where (𝐰,b) are the parameters of the hyperplane and 𝐱 is the input variable(s). When t and y have the same sign (meaning y predicts the correct class) and |y|≥1, the hinge loss ℓ(y)=0. When they have opposite signs, ℓ(y) increases linearly with y, and similarly if |y|<1, even if it has the same sign (correct prediction, but not by enough margin). Hinge loss is not a proper scoring rule.

Extensions While binary SVMs are commonly extended to multiclass classification in a one-vs-all or one-vs-one fashion, it is also possible to extend hinge loss itself for such an end. Several different variations of multiclass hinge loss have been proposed. For example, Crammer and Singer defined it for a linear classifier as

ℓ(y)=max⁡(0,1+maxy≠t𝐰y𝐱−𝐰t𝐱), where t is the target label, 𝐰t and 𝐰y are the model parameters. Weston and Watkins provided a similar definition, but with a sum rather than a max:

ℓ(y)=∑y≠tmax⁡(0,1+𝐰y𝐱−𝐰t𝐱). In structured prediction, hinge loss can be further extended to structured output spaces. Structured SVMs with margin rescaling use the following variant, where w denotes the SVM's parameters, y the SVM's predictions, φ the joint feature function, and Δ the Hamming loss:

ℓ(𝐲)=max⁡(0,Δ(𝐲,𝐭)+⟨𝐰,ϕ(𝐱,𝐲)⟩−⟨𝐰,ϕ(𝐱,𝐭)⟩)=max⁡(0,maxy∈𝒴(Δ(𝐲,𝐭)+⟨𝐰,ϕ(𝐱,𝐲)⟩)−⟨𝐰,ϕ(𝐱,𝐭)⟩).

Optimization Hinge loss is a convex function, so many of the usual convex optimizers used in machine learning can work with it. It is not differentiable, but has a subgradient with respect to model parameters w of a linear SVM with score function y=𝐰⋅𝐱 that is given by

∂ℓ∂wi={−t⋅xiif t⋅y<1,0otherwise.

However, since the derivative of the hinge loss at ty=1 is undefined, smoothed versions may be preferred for optimization, such as Rennie and Srebro's

ℓ(y)={12−tyif ty≤0,12(1−ty)2if 0<ty<1,0if 1≤ty or the quadratically smoothed

ℓγ(y)={12γmax⁡(0,1−ty)2if ty≥1−γ,1−γ2−tyotherwise suggested by Zhang. The modified Huber loss L is a special case of this loss function with γ=2, specifically L(t,y)=4ℓ2(y).

See also Multivariate adaptive regression spline § Hinge functions

References

Illustrations

Hinge loss: The vertical axis represents the value of the hinge loss (in blue) and zero-one loss (in green) for fixed .mw-parser-output .texhtml{font-family:"Nimbus Roman No9 L","Times New Roman",Times,serif;font-size:118%;line-height:1;font-variant-numeric:lining-nums tabular-nums;font-kerning:none}.mw-parser-output .texhtml .texhtml{font-size:100%}.mw-parser-output .texhtml-big{font-size:165%}.mw-parser-output .mvar{font-style:italic}@media(min-width:420px){.mw-parser-output .texhtml{white-space:nowrap}}t = 1, while the horizontal axis represents the value of the prediction y. The plot shows that the hinge loss penalizes predictions y < 1, corresponding to the notion of a margin in a support vector machine.
The vertical axis represents the value of the hinge loss (in blue) and zero-one loss (in green) for fixed .mw-parser-output .texhtml{font-family:"Nimbus Roman No9 L","Times New Roman",Times,serif;font-size:118%;line-height:1;font-variant-numeric:lining-nums tabular-nums;font-kerning:none}.mw-parser-output .texhtml .texhtml{font-size:100%}.mw-parser-output .texhtml-big{font-size:165%}.mw-parser-output .mvar{font-style:italic}@media(min-width:420px){.mw-parser-output .texhtml{white-space:nowrap}}t = 1, while the horizontal axis represents the value of the prediction y. The plot shows that the hinge loss penalizes predictions y < 1, corresponding to the notion of a margin in a support vector machine.
Hinge loss: Plot of three variants of hinge loss as a function of z = ty: the "ordinary" variant (blue), its square (green), and the piece-wise smooth version by Rennie and Srebro (red). The y-axis is the l(y) hinge loss, and the x-axis is the parameter t
Plot of three variants of hinge loss as a function of z = ty: the "ordinary" variant (blue), its square (green), and the piece-wise smooth version by Rennie and Srebro (red). The y-axis is the l(y) hinge loss, and the x-axis is the parameter t

Worked examples

Example 1 — a first encounter with Hinge loss

Start with the simplest possible case. Write down what Hinge loss claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Hinge loss before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Hinge loss ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Hinge loss

In research
Hinge loss appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Hinge loss in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Hinge loss is common in secondary-school and first-year university syllabi. It links to neighbouring topics Loss functions, Support vector machines, so understanding it makes those chapters shorter.
In everyday life
Look for Hinge loss outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Hinge loss” →

How to study Hinge loss in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Hinge loss means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Hinge loss out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Hinge loss in simple terms?

In machine learning, hinge loss is a loss function used for training classifiers. Hinge loss is used for "maximum-margin" classification, most notably for support vector machines (SVMs).

Why does Hinge loss matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Hinge loss?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Hinge loss.

Tags

  • Loss functions
  • Support vector machines

Keep exploring