Maximum margin and hinge loss
Quick answer
A support vector classifier separates classes using a decision score. A linear score is f(x)=w·x+b; its sign determines the binary class. Maximum-margin training looks for a wide separation between the two classes, while hinge loss measures violations of the desired signed margin. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Compute margin violations
scores=[-2,-0.5,0.25,2]y=[-1,1,1,-1]print([max(0,1-a*b) for a,b in zip(y,scores)])Observed local output:
[0, 1.5, 0.75, 3]The last point is confidently wrong, so its loss is largest.
How it works
Encode the two classes as -1 and +1 for this derivation. The functional margin of a labeled observation is m=yf(x). Positive m indicates correct classification (except at the zero tie); m>=1 satisfies the canonical margin constraint. Hinge loss is max(0,1-m). A correctly classified observation can still incur loss: y=1, f=0.25 gives loss 0.75. With w nonzero, the geometric signed margin is m/||w||; the unsigned distance to the decision plane is |f|/||w||. Scaling both w and b by a positive constant leaves the decision boundary unchanged but alters the functional margin. In the separable hard-margin formulation, require y_if(x_i)>=1 and minimize ||w||²/2. Then the two canonical margin planes f=-1 and f=1 are separated by 2/||w||. For training points -2,-1 (negative) and 1,2 (positive), w=1 and b=0 are optimal: constraints force w>=1, and this choice attains it. The closest points -1 and 1 define the separation. This does not imply real-world generalization is guaranteed. Soft margins relax these constraints in the next lesson. SVC uses supplied class labels directly; the -1/+1 mapping is a mathematical convention, not a required input encoding. For binary linear SVC, use the coefficient norm to convert the decision score to distance in the feature space used for training.
Inspect the separating margin
from sklearn.svm import SVCm=SVC(kernel="linear",C=10).fit([[-2],[-1],[1],[2]],[-1,-1,1,1])print(m.support_vectors_.ravel().tolist())print(m.decision_function([[-1],[0],[1]]).tolist())Observed local output:
[-1.0, 1.0][-1.0, -0.0, 1.0]The support vectors are at the canonical margin planes; zero is the boundary, not a probability.
Common mistakes
Do not call every positive score a zero-loss prediction or interpret a raw score as a probability. A score of zero lies on the boundary; use the fitted estimator for its tie behavior. Distinguish the full margin width from the distance to one margin plane. The geometric formula is for nonzero linear weights in the stated feature coordinates.
Practice and next steps
For w=(3,4), b=-5, x=(2,1) and y=+1, compute the score, hinge loss and geometric signed margin. Answer: 5, 0 and 1. Then change y to -1 and explain why the loss increases to 6. Complete the knowledge check and staged exercise. Next: Soft margin and C.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Maximum margin and hinge loss — knowledge check
Apply maximum margin and hinge loss to new scenarios.
A positive signed margin of 0.25 has hinge loss?
What is the boundary?
What happens to the geometric distance if w and b are doubled?
If ||w||=4, full canonical margin width?
What does a margin score alone establish?