WHAT the linear SVM does: it finds a separating hyperplane w⊤x+b=0. Its decision function, after training, can be written using only dot products between the query point x and the support vectors xi:
f(x)=∑iαiyi(xi⊤x)+b
WHY this matters: the data xonly ever appears inside a dot productxi⊤x. So if the data isn't linearly separable in its raw form, we can map it with ϕ(x) into a richer space and hope it becomes separable there. Then the decision function needs ϕ(xi)⊤ϕ(x).
HOW the trick saves us: computing ϕ(x) explicitly can be expensive or infinite-dimensional. But if there's a function K with
K(x,z)=ϕ(x)⊤ϕ(z)
we never build ϕ. We just replace every dot product by K. That replacement is the whole game.
Derivation. Take ϕ(x)=x. Then ϕ(x)⊤ϕ(z)=x⊤z=K(x,z). Done. It is a kernel with the identity feature map. Use it when d is large and data is already ~linearly separable (text, sparse features).
Why this step? Group each term as (something in x)×(same something in z). That grouping is a dot product ϕ(x)⊤ϕ(z) with
ϕ(x)=(x12,x22,2x1x2,2x1,2x2,1)
So a degree-2 polynomial kernel silently gives you all squares, cross-terms and linear terms — a 6-dimensional feature space from 2 inputs, computed with one dot product and one square. The c controls how much weight low-order terms get; larger c → more emphasis on lower-degree features.
Why this step? Each (x⊤z)k is itself a (homogeneous) polynomial kernel of degree k, i.e. a dot product in a finite space. A weighted sum of kernels is a kernel, and here the sum runs to infinity → RBF corresponds to an infinite-dimensional feature map containing polynomial features of every degree. That's why it's so expressive.
Replacing every dot product x⊤z in an algorithm by K(x,z)=ϕ(x)⊤ϕ(z), gaining a high-dim feature space without computing ϕ.
Formula for the linear kernel?
K(x,z)=x⊤z, with feature map ϕ(x)=x.
Formula for the polynomial kernel?
K(x,z)=(γx⊤z+c)d.
Formula for the RBF/Gaussian kernel?
K(x,z)=exp(−γ∥x−z∥2).
What condition makes a function a valid kernel?
Its Gram matrix is symmetric positive semi-definite (Mercer's theorem).
Feature map of degree-2 poly kernel (x⊤z+1)2 in 2D?
(x12,x22,2x1x2,2x1,2x2,1).
Why is RBF infinite-dimensional?
Because e2γx⊤z=∑kk!(2γ)k(x⊤z)k mixes polynomial kernels of every degree.
Effect of large γ in RBF?
Very local influence → wiggly boundary → overfitting risk.
Effect of small γ in RBF?
Smooth, near-linear boundary → underfitting risk.
When prefer the linear kernel?
High-dimensional sparse data (text) where nonlinearity would overfit; also for speed.
Why must you scale features before RBF/poly?
They depend on ∥x−z∥2/x⊤z, which are dominated by large-magnitude features.
Recall Feynman: explain to a 12-year-old
Imagine judging how "alike" two toys are. The linear way: line them up and see how much they point the same direction. The polynomial way: also compare their combinations — colour AND size together, not just each alone. The RBF way: just measure how close together they are — touching toys are "1", far-apart toys are "0". The magic trick is that a computer can measure this alikeness directly, without ever building the giant table of every possible combination. That shortcut lets the SVM draw curvy fences between groups while only doing simple arithmetic.
Socho SVM ke paas ek problem hai: data seedhi line se separate nahi ho raha. Solution kya hai? Data ko kisi bade dimension me le jao jahan wo separate ho jaye. Lekin bade dimension me har point ka features compute karna mehenga hai. Yahan kernel trick aata hai: SVM ko sirf dot product chahiye, poora feature vector nahi. Agar humare paas ek function K(x,z) hai jo directly ϕ(x)⊤ϕ(z) de de, to hum bina us bade space me gaye kaam chala lete hain. Yehi jaadu hai.
Teen popular kernels hain. LinearK=x⊤z — bas raw alignment, jab data pehle se lineary separable ho (text data, sparse features) tab best. PolynomialK=(γx⊤z+c)d — ye andar hi andar features ke combinations (cross-terms jaise x1x2) bana deta hai, jisse curvy boundary ban jaati hai. RBFK=e−γ∥x−z∥2 — ye do points ki nazdeeki naapta hai; same point pe K=1, door jaate hi K girta hai. Iska ek Taylor expansion nikaalo to pata chalta hai ki ye infinite-dimensional feature space ke barabar hai — isliye sabse powerful hai.
Sabse important knob hai γ (RBF me) aur degree (poly me). Zyada γ = har point ka asar sirf apne chhote area tak = bahut wiggly boundary = overfitting. Kam γ = smooth, almost linear. Iska matlab ye bias–variance ka control hai, jise cross-validation se tune karte ho. Practical tip (80/20 rule): pehle linear try karo, kaam na kare to RBF try karo, aur features ko hamesha standardize karo warna badi magnitude wala feature sab pe haavi ho jaayega.
Test yourself — SVM, Naive Bayes & Probabilistic Models