Support Vector Machines and Support Vector Regression › Example
Machine Learning from ScratchAll chapters Support Vector Machines and Support Vector Regression › ExampleSection view · Sections in this chapter6 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Two points suffice to work the margin calculation by hand. Let
where:
- : the two training inputs
- : their corresponding labels
The hard-margin problem for these two points is
We can prove the symmetry rather than assume it. Let . The two constraints imply , while , with equality only when . Hence the objective is at least . Equality is attained by and , proving global optimality. At this solution both margin constraints are tight:
Both equations reduce to . Under the symmetry assumption we find , so and . The margin width is
and the decision boundary is the line .
To connect this back to the dual, let be the multipliers. The KKT stationarity condition gives
Since , stationarity requires . The balance condition gives . These hard-margin multipliers are feasible for the soft-margin box constraints when , so the same zero-slack solution is optimal there. For , the dual optimum has and . Choosing then gives both points functional margin . In fact every is optimal in this regime, showing that the unpenalized bias need not be unique.
Returning to the hard-margin solution, which is also the soft-margin solution for , we can check strong duality. Its primal objective is
Because both points sit exactly on the margin, their slack values are zero and the hinge-loss sum vanishes, so the primal objective equals the margin term alone. This is the dual echo of the geometric statement that the two closest points fully determine the boundary.
We can verify the calculation with the dual objective. Note that
so the cross term carries a negative label product , and the negative inner product makes the product positive. Thus
and the dual objective equals
where:
- : the optimal dual multipliers from the stationarity condition
- : the labels and
- : the pairwise inner products, and
- : the value of the double sum computed above
The dual objective value matches the primal value , which is consistent with strong duality.
Now consider a slightly harder case that exercises the soft margin. Add a third point with . Keep the original candidate and ; rescaling it would change the functional margins used by the objective. For the third point,
Its smallest feasible slack at this candidate is therefore
The original two points still have zero slack, so this candidate has objective . This is a feasible value, not proof that the candidate is optimal.
In fact, this dataset has a useful structure: the positive point lies between two negative points on the same line. For every , the exact soft-margin optimum is the constant classifier
It predicts the negative class for all three points, pays hinge loss two for the positive point, and has objective . We can prove optimality using the dual multipliers
They satisfy the box constraints and , and they give
The dual objective is consequently , matching the primal value. A feasible primal value matching a feasible dual value establishes global optimality.
Here changes the objective value without changing the fitted classifier. The usual margin-versus-loss tradeoff does not promise that the boundary moves whenever changes. Since , this constant solution has no separating hyperplane with a finite margin width ; the soft-margin objective is still well defined.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!