WHAT is the problem? A linear SVM finds a separating hyperplane w⊤x+b=0. But data like concentric circles (inner class vs outer ring) has no straight line that separates them.
WHY does lifting help? If we add a feature like x12+x22 (distance-squared from origin), the inner points get a small value and the outer ring a large value — now a flat threshold on that new axis separates them perfectly.
HOW without exploding cost? A degree-d polynomial map on n features has O(nd) new features. Computing them explicitly is expensive (or infinite-dimensional!). The kernel trick sidesteps this: the SVM's math only ever uses dot products⟨xi,xj⟩, so if we can compute ⟨ϕ(xi),ϕ(xj)⟩ cheaply via a shortcut function, we never form ϕ(x) at all.
Why this matters: the training data appears only as the inner product ⟨xi,xj⟩. Prediction is also purely dot products:
f(x)=sign(∑iαiyi⟨xi,x⟩+b).
So replace every ⟨xi,xj⟩ with K(xi,xj)=⟨ϕ(xi),ϕ(xj)⟩ and you get a nonlinear SVM for free.
Let's prove the polynomial kernel is a dot product in a bigger space. Take 2D inputs x=(x1,x2), z=(z1,z2) and the function
K(x,z)=(x⊤z)2.
Step 1 — expand.Why? We want to see if it factors as ϕ(x)⊤ϕ(z).
(x1z1+x2z2)2=x12z12+2x1x2z1z2+x22z22.
Step 2 — regroup as a dot product.Why? Group terms so each summand is (function of x)×(same function of z).
=(x12)(z12)+(2x1x2)(2z1z2)+(x22)(z22).
Step 3 — read off ϕ.Why? It now literally is ϕ(x)⊤ϕ(z) with
ϕ(x)=(x12,2x1x2,x22).
When is a function K a valid kernel? By Mercer's theorem: iff K is symmetric and the Gram matrix [K(xi,xj)] is positive semidefinite for every dataset. PSD guarantees some feature map ϕ exists.
Why is RBF infinite-dimensional? Expand e2γx⊤z as a Taylor series ∑kk!(2γx⊤z)k: it contains polynomial terms of every degree. Each degree adds features, so ϕ has infinitely many — impossible to compute explicitly, trivial to evaluate as a kernel. This is why the kernel trick is essential, not just convenient.
Imagine trying to separate red marbles inside a circle from blue marbles outside, all lying flat on a table. No straight stick can split them. Now lift the middle of the table up like a hill — reds rise high, blues stay low. Now a flat card can slide between them! The kernel trick is a magic ruler that tells you how far apart marbles would be after lifting, without ever building the hill. You get the answer for free.
Dekho, kabhi-kabhi data aisa hota hai ki koi bhi seedhi line usse alag nahi kar sakti — jaise ek chhota circle andar aur bada circle bahar. Aisi situation mein hum data ko ek higher-dimensional space mein "utha" lete hain, jahan wahi data ek flat plane se easily separate ho jaata hai. Yeh uthana kaam karta hai feature map ϕ se — jaise x12+x22 (origin se distance-squared) add kar diya.
Ab problem yeh hai ki agar features bahut zyada ho jaayein (polynomial degree d pe O(nd), ya RBF pe toh infinite!), toh unhe explicitly compute karna mushkil ya impossible hai. Yahan aata hai kernel trick ka jaadu: SVM ki dual form mein data sirf dot products ke roop mein aata hai. Toh hum ϕ banate hi nahi — bas ek function K(x,z)=⟨ϕ(x),ϕ(z)⟩ use karte hain jo seedha original space mein sasta compute ho jaata hai.
Sabse common kernels: linear, polynomial (x⊤z+c)d, aur RBF exp(−γ∥x−z∥2). RBF ek "closeness" measure hai — paas ke points ka similarity 1 ke kareeb, door ke points ka 0 ke kareeb. Ek cheez yaad rakho: har similarity function kernel nahi hota — usse Mercer condition (symmetric + PSD Gram matrix) satisfy karna padta hai. Aur γ bada rakhoge toh model overfit karega, isliye tuning zaroori hai. Bas itna samajh lo, toh non-linear SVM tumhare liye clear ho gaya.
Test yourself — SVM, Naive Bayes & Probabilistic Models