A linear classifier has w=(2,−1) and b=0.5. What are the hinge loss and the 0–1 loss on the points A=(1,0) with label +1, B=(0,0) with label +1, and C=(1,1) with label −1?

Supervised learning, Hinge loss
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you can evaluate the hinge loss max⁡(0,1−yf(x)) and see how it differs from the 0–1 loss.

Key idea

For a score f(x)=w⊤x+b and label y∈{−1,+1}, the hinge loss is max⁡(0, 1−yf(x)). It is zero only when the point is correctly classified with a margin of at least 1.

Steps

  1. Write the score f(x)=2x1−x2+0.5.
  2. Point A: f=2(1)−0+0.5=2.5 and yf=2.5. Hinge loss =max⁡(0,1−2.5)=0. The 0–1 loss is 0 because the sign is correct.
  3. Point B: f=0.5 and yf=0.5. Hinge loss =max⁡(0,1−0.5)=0.5. The 0–1 loss is 0, because B is on the right side but inside the margin.
  4. Point C: f=2−1+0.5=1.5 and yf=−1.5. Hinge loss =max⁡(0,1+1.5)=2.5. The 0–1 loss is 1 because the sign is wrong.
  5. Summarise: hinge loss also penalises correct points that are too close to the boundary (like B), and it grows linearly for wrong points. The 0–1 loss does neither.

Common mistakes

How long your answer should be

Three one-line calculations and a one-sentence comparison.

Read this

Previous in Supervised learning: A three-class softmax model produces scores (logits) z=(2,1,0) for an input. Compute the class probabilities. If the true class is class 2, what is the cross-entropy loss, and what is the gradient of the loss with respect to z?
Next in Supervised learning: What is the difference between multiclass and multilabel classification, and how do the output activation, the loss and the prediction rule differ for a neural or linear model with L outputs? What are three ways to reduce multilabel to simpler problems?