Suppose two classes are linearly separable. There are infinitely many lines that separate them perfectly (0 training errors). Which one is "best"?
The points that touch the edge of the street are the support vectors. They alone define the boundary — remove all other points and the answer is unchanged.
Step 1 — Distance from a point to the hyperplane.
Take a point x0. Move perpendicular to the plane (along w/∥w∥) by distance r to reach the plane at xp:
x0=xp+r∥w∥w.Why this step? Any shortest path to a plane is along its normal.
Apply w⊤(⋅)+b and use w⊤xp+b=0:
w⊤x0+b=r∥w∥w⊤w=r∥w∥.
So the signed distance is
r=∥w∥w⊤x0+b.
Step 2 — Fix the scale (the clever trick).w,b can be scaled freely: (w,b) and (2w,2b) describe the same plane. We remove this ambiguity by choosing the scale so that the closest points satisfy
mini∣w⊤xi+b∣=1.Why this step? It pins one degree of freedom, turning a messy ratio into a clean constraint. This is the canonical hyperplane.
Step 3 — Compute the margin width.
With that scaling, the nearest point has ∣w⊤xi+b∣=1, so its distance is 1/∥w∥. The street has this on both sides:
margin=∥w∥2.
Form the Lagrangian with multipliers αi≥0:
L=21∥w∥2−∑iαi[yi(w⊤xi+b)−1].
Stationarity gives
∂w∂L=0⇒w=∑iαiyixi,∂b∂L=0⇒∑iαiyi=0.Why this matters:w is a weighted sum of the data points. Complementary slackness says αi[yi(w⊤xi+b)−1]=0, so αi>0 only for points exactly on the margin (yi(w⊤xi+b)=1). Those are the support vectors; all others have αi=0 and drop out.
Imagine two groups of kids on a playground, and you must paint one straight line so each group stays on its own side. You could paint many lines. The best line leaves the biggest empty walkway between the two groups, so if a kid wiggles a little they still don't cross. The kids standing right at the edge of the walkway are the "important" kids — they decide where the line goes. All the kids far in the back don't matter at all.
Socho do class ke points hain aur tumhe ek straight line se unhe alag karna hai. Problem yeh hai ki aisi infinite lines ho sakti hain jo perfectly separate kar dein — toh best kaunsi? SVM ka jawab: woh line jo dono groups ke sabse nazdeek points se maximum door ho. Matlab beech mein sabse chaudi gali (street) banao. Yeh isliye best hai kyunki agar test point mein thoda noise aa jaye, tab bhi woh galat side par cross nahi karega — yani generalization achha hota hai.
Ek important baat jo log galti karte hain: yeh mat maan lo ki boundary hamesha vertical ya horizontal hogi. Actually max-margin line closest opposite-class pair ko jodne wale vector ke perpendicular hoti hai — jo aksar diagonal hoti hai. Humare 2D example mein closest pair (3,3) aur (1,1) hai, gap vector (2,2), toh w=(21,21) nikalta hai aur margin 22≈2.83 banta hai — vertical boundary ka margin sirf 2 hota, jo chhota hai.
Math clean karne ke liye labels +1 aur −1 lete hain, aur scaling trick: closest point par ∣w⊤x+b∣=1. Isse margin width =2/∥w∥. Margin bada karna hai toh ∥w∥ chhota karo — isiliye 21∥w∥2 minimize karte hain, constraint yi(w⊤xi+b)≥1 ke saath.
Sabse mast baat: sirf margin ki edge par khade points boundary decide karte hain — inhe support vectors kehte hain. Baaki hata do, answer nahi badlega. Naya point classify karna simple: sign(w⊤x+b) dekh lo.
Test yourself — SVM, Naive Bayes & Probabilistic Models