WHAT is the distance from a point x0 to the hyperplane w⊤x+b=0?
Why this step? Geometry: move from x0 along the unit normal w/∥w∥ until you hit the plane. The signed distance is
d=∥w∥w⊤x0+b.
We have freedom to scalew and b by any constant — the hyperplane is unchanged. So we fix the scale by demanding that the closest points satisfy ∣w⊤x+b∣=1. This is the canonical form.
Why this step? It removes the ambiguity so the optimization is well-posed. With this choice the margin (distance to the nearest point) becomes
γ=∥w∥1,full gap width=∥w∥2.
So maximizing the margin=minimizing ∥w∥= minimizing 21∥w∥2 (the square and 21 are just for a nicer, convex, differentiable objective).
We introduce a slack variable ξi≥0 per point: how far point i is allowed to violate its margin constraint.
yi(w⊤xi+b)≥1−ξi,ξi≥0.
HOW to read ξi:
ξi=0: point is safely outside the margin (obeys hard constraint).
0<ξi≤1: inside the margin but still correctly classified.
ξi>1: misclassified (on the wrong side of the boundary).
We don't want unlimited cheating, so we penalize the total slack:
WHY the C?C is the trade-off knob between a wide margin and few violations.
Large C → violations are very expensive → model tries hard to classify all points → narrow margin, low bias, high variance → approaches hard margin as C→∞.
Small C → cheap to violate → wide margin, more tolerance to noise, high bias, low variance.
At the optimum, each ξi is as small as allowed. The constraints force
ξi=max(0,1−yi(w⊤xi+b)).
Why this step? If the point already satisfies yi(…)≥1, no slack needed → ξi=0. Otherwise ξi must cover the gap exactly. Substituting turns the constrained problem into an unconstrained one:
Only points with ξi>0or lying exactly on the margin (yi(…)=1) have nonzero influence — these are the support vectors. Points comfortably outside the margin can be deleted without changing the boundary. WHY? In the dual, their Lagrange multipliers αi=0.
Recall Feynman: explain to a 12-year-old
Imagine drawing a fence between the cats and the dogs in a park. A hard fence rule says: no animal may touch or cross the fence, ever. That's fine until one confused cat wanders into dog-land — now you can't draw any fence at all! The soft rule says: try to keep them apart with the widest safe path, but if a few troublemakers cross, that's okay — just count how badly they cross and try to keep that small. The knob C is how angry you get at troublemakers: big C = very strict, small C = chill and forgiving.
With canonical scaling ∣w⊤x+b∣=1 at closest points, margin =1/∥w∥, so wider margin means smaller norm. ::: We minimize 21∥w∥2 for convexity/differentiability.
Write the hard margin constraint.
yi(w⊤xi+b)≥1 for all i.
When does the hard margin SVM have NO solution?
When the data is not linearly separable (constraints are infeasible).
What is a slack variable ξi?
A nonnegative amount by which point i is allowed to violate its margin constraint: yi(w⊤xi+b)≥1−ξi.
Dekho, SVM ka main idea ye hai ki do classes ke beech me hum aisi line (ya hyperplane) khichte hain jo dono ke sabse pass wale points se maximum door ho. Is gap ko margin bolte hain, aur wo 2/∥w∥ hota hai. To margin bada karna matlab ∥w∥ chhota karna — isliye hum 21∥w∥2 minimize karte hain. Wide margin zyada robust hota hai, thoda sa noise aane par bhi prediction nahi badalti.
Hard margin kehta hai: koi bhi point margin ke andar ya galat side me nahi aana chahiye — 100% perfect separation. Problem ye hai ki agar data thoda bhi overlap kare ya ek bhi outlier ho, to koi solution hi nahi banta, aur model overfit ho jaata hai. Isliye real duniya me hard margin kaam nahi karta.
Yahan aata hai soft margin. Har point ke liye ek slack variable ξi dete hain — matlab "thoda cheating allowed hai". ξi=0 matlab point safe hai, 0<ξi≤1 matlab margin ke andar par sahi side, aur ξi>1 matlab galat classify ho gaya. Total cheating ko penalize karte hain C∑ξi se. Ye pura cheez hinge loss ke barabar hai: max(0,1−yi(w⊤xi+b)).
C ek knob hai. Bada C = strict teacher, violations ko bahut mehnga maanega, narrow margin, overfit. Chhota C = chill teacher, wide margin, noise ko ignore karega, better generalization. Jab C→∞, soft margin wapas hard margin ban jaata hai. Exam me yaad rakho: "Hard = zero tolerance, Soft = slack with a Cost."
Test yourself — SVM, Naive Bayes & Probabilistic Models