MIT15 097S12 Lec12
MIT15 097S12 Lec12
The margin is positive if the example is on the correct side of the decision bound-
ary, otherwise it’s negative.
1
Most other algorithms (logistic regression, decision trees, perceptron) don’t gen-
erally produce large margins. (AdaBoost generally produces large margins.)
Note that the intercept term can get swept into x by adding a 1 as the last
component of each x. Then f (x) would be just λT x but for this lecture we’ll
keep the intercept term separately because SVM handles that term differently
than if you put the intercept as a separate feature. We classify x using sign(f (x)).
2
SVM’s maximize the distance from the decision boundary to the nearest training
example – they maximize the minimum margin. There is a geometric perspective
too. I set the intercept to zero for this picture (so the decision boundary passes
through the origin):
The decision boundary are x’s where λT x = 0. That means the unit vector for
λ must be perpendicular to those x’s that lie on the decision boundary.
Now that you have the intuition, we’ll put the intercept back, and we have to
translate the decision boundary, so it’s really the set of x’s where λT x = λ0 .
3
since we moved −γi units along the unit vector to get from the example to B.
If the example is negative, the same calculation works, with a few sign flips (we’d
need to move γi units rather than −γi units).
So the “geometric” margin from the picture is the same as the “functional”
margin yi f˜(xi ).
λT xi + λ0
max γ s.t. yi ≥γ i = 1...m
γ,λ,λ0 ||λ||2
4
For any λ and λ0 that satisfy this, any positively scaled multiple satisfies them
too, so we can arbitrarily set ||λ||2 = 1/γ so that the right side is 1.
(the 1/2 and square are just for convenience) which is the same as:
1
min ||λ||22 s.t. − yi (λT xi + λ0 ) + 1 ≤ 0 i = 1 . . . m
λ,λ0 2
5
Using the KKT conditions, we can simplify the Lagrangian.
m m m
1 X X X
L ([λ, λ0 ], α) = kλk22 + λT (−αi yi xi ) + (−αi yi λ0 ) + αi
2 i=1 i=1 i=1
(We just expanded terms. Now we’ll plug in the first KKT condition.)
m m
1 2 2
X X
= ||λ||2 − ||λ||2 − λ0 (αi yi ) + αi
2 i=1 i=1
(Plug in the second KKT condition.)
m m
1 X (j)2 X
=− λ + 0 + αi (2)
2 j=1 i=1
Again using the first KKT condition, we can rewrite the first term.
m m m
!2
1 X (j)2 1X X (j)
− λ =− αi y i x i
2 j=1 2 j=1 i=1
m m m
1 XXX (j) (j)
=− αi αk yi yk xi xk
2 j=1 i=1
k=1
m X
m
1 X
=− αi αk yi yk xTi xk .
2 i=1 k=1
Plugging back into the Lagrangian (2), which now only depends on α, and
putting in the second and third KKT conditions gives us the dual problem;
max L (α)
α
where
m
Pi m≥ 0 i = 1 . . . m
X 1X α
L (α) = αi − αi αk yi yk xTi xk s.t. (3)
i=1
2
i,k i=1 αi yi = 0
We’ll use the last two KKT conditions in what follows, for instance to get con-
ditions on λ0 , but what we’ve already done is enough to define the dual problem
for α.
We can solve this dual problem. Either (i) we’d use a generic quadratic pro-
gramming solver, or (ii) use another algorithm, like SMO, which I will discuss
6
later. For now, assume we solved it. So we have α1∗ , . . . , αm
∗
. We can use the
solution of the dual problem to get the solution of the primal problem. We can
plug α∗ into the first KKT condition to get
m
X
∗
λ = αi∗ yi xi . (4)
i=1
We still need to get λ∗0 , but we can see something cool in the process.
Support Vectors
Look at the complementary slackness KKT condition and the primal and dual
feasibility conditions:
∗
αi > 0 ⇒ yi (λ∗T xi + λ∗0 ) = 1
∗
∗
∗T ∗
αi < 0 (Can’t happen)
αi −yi (λ xi + λ0 ) + 1 = 0 ⇒
−yi (λ∗T xi + λ∗0 ) + 1 < 0 ⇒ αi∗ = 0
−yi (λ∗T xi + λ∗0 ) + 1 > 0 (Can’t happen)
Define the optimal (scaled) scoring function: f ∗ (xi ) = λ∗T xi + λ∗0 , then
7
1
1
Support vectors
x2
x1
Image by MIT OpenCourseWare.
λ∗0 = 1 − λ∗T xi .
Written another way, since the support vectors have the smallest margins,
So that’s the solution! Just to recap, to get the scoring function f ∗ for SVM,
you’d compute α∗ from the dual problem (3), plug it into (4) to get λ∗ , plug that
into the equation above to get λ∗0 , and that’s the solution to the primal problem,
and the coefficients for f ∗ .
8
Because of the form of the solution:
m
X
∗
λ = αi∗ yi xi .
i=1
there is no feasible solution to the problem we wrote above. Most real problems
are nonseparable.
Let’s fix our SVM so it can accommodate the nonseparable case. The new for-
mulation will penalize mistakes the farther they are from the decision boundary.
So we are allowed to make mistakes now, but we pay a price.
9
Let’s change our primal problem (1) to this new primal problem:
m
yi (λT xi + λ0 ) ≥ 1 − ξi
1 X
min ||λ||22 + C ξi s.t. (5)
λ,λ0 ,ξ 2 ξi ≥ 0
i=1
So the constraints allow some slack of size ξi , but we pay a price for it in the
objective. That is, if yi f (xi ) ≥ 1 then ξi gets set to 0, penalty is 0. Otherwise,
if yi f (xi ) = 1 − ξi , we pay price ξi .
Parameter C trades off between the twin goals of making the ||λ||22 small (making
what-was-the-minimum-margin 1/ ||λ||22 large) and ensuring that most examples
have margin at least 1/ ||λ||22 .
10
The Dual for the Nonseparable Case
Form the Lagrangian of (5):
m m m
1 X X X
L(λ, b, ξ , α, r) = ||λ||22 + C ξi − αi yi (λT xi + λ0 ) − 1 + ξi − ri ξi
2 i=1 i=1 i=1
So the only difference from the original problem’s Lagrangian (3) is that 0 ≤ αi
was changed to 0 ≤ αi ≤ C. Neat!
Start with (6). Let’s say you want to hold α2 , . . . , αm fixed and take a coordinate
step in the first direction. That is, change α1 to maximize the objective in (6).
Can we make any progress? Can we get a better feasible solution by doing this?
Pm
Turns out, no. Look at the constraint in (6), i=1 αi yi = 0. This means:
m
X
α 1 y1 = − αi yi , or multiplying by y1 ,
i=2
Xm
α1 = −y1 αi yi .
i=2
11
So, if we want to update any of the αi ’s, we need to update at least 2 of them
simultaneously to keep the solution feasible (i.e., to keep the constraints satis-
fied).
1X
max α1 + α2 + constants − αi αk yi yk xTi xk where α1 = y1 (ζ − α2 y2 ).
α2 ∈[L,H] 2
i,k
(7)
The objective is quadratic in α2 . This means we can just set its derivative to 0
to optimize it and get α2 for the next iteration of SMO. If the optimal value is
12
outside of [L,H], just choose α2 to be either L or H for the next iteration.
For instance, if this is a plot of (7)’s objective (sometimes it doesn’t look like
this, sometimes it’s upside-down), then we’ll choose :
13
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.