Skip to content
PostMachine Learning / Lecture

SVM

2024-11-11
Back to Blog

SVM optimization problem ​

minw,b12||w||2subject to yi(wTXi+b)≥1,i=1,…,myi(wTxi+b)≥1,i=1,2,…,m
  • We can write the constraints as

    gi(w)=1−yi(wTxi+b)≤0
  • When we construct the Lagrangian for our optimization problem, we have:

    L(w,b,α)=12∥w∥2+∑i=1mαi[1−yi(wTxi+b)]
  • Let’s find the dual form of the problem.

    • First minimize L(w,b,α) with respect to w and b (for fixed α), to get θD(α).
  • We’ll do this by setting the derivatives of L with respect to w and b to zero:

    ∂∂wL(w,b,α)=w−∑i=1mαiyixi=0∂∂bL(w,b,α)=∑i=1m−αiyi=0
  • We have: $$w = \sum_{i=1}^m \alpha_i y_i x_i$$ and $$\sum_{i=1}^m \alpha_i y_i = 0$$. Plugging back into the Lagrangian equation:

    L(w,b,α)=12∥w∥2+∑i=1mαi[1−yi(wTxi+b)]=∑i=1mαi−12∑i=1m∑j=1mαiαjyiyjxiTxj−b∑i=1mαiyi=∑i=1mαi−12∑i=1m∑j=1mαiαjyiyjxiTxj

Hard SVM ​

Hyperplane: H={w|wTx+b=0}Constraint: yi(wTxi+b)≥1 ∀iGoal: min12||w||2 s.t. yi(wtxi+b)≥1Lagrangian:L(w,b,α)=12||w||2−∑iαi(yi(wTxi+b)−1),αi≥0Partial derivative: ∂L∂w=w−∑iαiyixi=0 ∂L∂b=−∑iαiyi=0Solution: ||w||2=(∑iαiyixi)T(∑iαiyixi)=∑i∑jαiαjyiyjxiTxjLagrangian becomes: L=∑iαi−12∑i∑jαiαjyiyjxiTxjs.t. ∑iαiyi=0 and αi≥0∀iWeight vector: w∗=∑iαiyixiBias: b∗=yi−∑iαiyixiTxj

Soft SVM ​

Hyperplane: H={w|wTx+b=0}Constraint: yi(wTxi+b)≥1−ξi,ξi≥0,∀iGoal: min12||w||2+C∑i=1nξi,s.t.yi(wTxi+b)≥1−ξi,ξi≥0
Lagrangian: L(w,b,α,ξ)=12||w||2+C∑i=1nξi−∑i=1nαi(yi(wTxi+b)−1+ξi)−∑i=1nμiξi,αi,μi≥0Partial Derivative: ∂L∂w=w−∑i=1nαiyixi=0,∂L∂b=−∑i=1nαiyi=0,∂L∂ξi=C−αi−μi=0Solution: ||w||2=∑i=1n∑j=1nαiαjyiyjxiTxjDual Problem: L=maxα∑i=1nαi−12∑i=1n∑j=1nαiαjyiyjxiTxjs.t. ∑i=1nαiyi=0,0≤αi≤C

Weight vector: w∗=∑i=1nαiyixiBias: b∗=yk−∑i=1nαiyixiTxkfor any 0<αk<C

The reason that ξ disappears: The slack variables ξi disappear in the dual problem because they are implicitly handled through the Lagrange multipliers αi. By taking the derivative of the Lagrangian with respect to ξi, we obtain:∂L∂ξi=C−αi−μi=0 This relationship ensures that αi is bounded by 0≤αi≤C. Consequently, the slack variables αi do not explicitly appear in the dual formulation. Instead, the dual problem balances maximizing the margin and allowing for misclassification through the constraint on αi.

Kernel SVM ​

Hyperplane: H={w|wTϕ(x)+b=0}Constraint: yi(wTϕ(xi)+b)≥1−ξi,ξi≥0,∀iGoal: min12||w||2+C∑i=1nξi,s.t.yi(wTϕ(xi)+b)≥1−ξiLagrangian (Dual): L(α)=∑i=1nαi−12∑i=1n∑j=1nαiαjyiyjK(xi,xj)s.t. ∑i=1nαiyi=0,0≤αi≤C,∀iWeight vector: w=∑i=1nαiyiϕ(xi)Decision Function: f(x)=sign(∑i=1nαiyiK(xi,x)+b)Bias: b=yk−∑i=1nαiyiK(xi,xk)∀sup vec 0<αk<CKernel Functions:
Linear: K(xi,xj)=xiTxj
Polynomial: K(xi,xj)=(xiTxj+c)d
Gaussian (RBF): K(xi,xj)=exp⁡(−||xi−xj||22σ2)
Sigmoid: K(xi,xj)=tanh⁡(κxiTxj+c)