2.4.3 · HinglishSVM, Naive Bayes & Probabilistic Models

The kernel trick

1,527 words7 min readRead in English

2.4.3 · AI-ML › SVM, Naive Bayes & Probabilistic Models


WHY hume iska zaroorat hai?

WHAT hai problem? Ek linear SVM ek separating hyperplane dhundtha hai. Lekin concentric circles jaisa data (inner class vs outer ring) ko koi bhi straight line separate nahi kar sakti.

WHY lifting help karti hai? Agar hum (origin se distance-squared) jaisi ek feature add karein, toh inner points ko ek chotti value milti hai aur outer ring ko ek badi value — ab us nayi axis par ek flat threshold unhe perfectly separate kar deta hai.

HOW bina cost explode kiye? features par ek degree- polynomial map mein nayi features hoti hain. Unhe explicitly compute karna expensive hai (ya infinite-dimensional!). Kernel trick isse sidestep karti hai: SVM ka math sirf dot products use karta hai, toh agar hum ko ek shortcut function se cheaply compute kar sakein, toh hum kabhi bhi nahi banaate.


Dual form: jahan dot products aate hain

Yeh kyun matter karta hai: training data sirf inner product ke roop mein appear hota hai. Prediction bhi purely dot products hai:

Toh har ko se replace karo aur tumhe free mein ek nonlinear SVM mil jaata hai.


SCRATCH SE ek kernel derive karna

Chalo prove karte hain ki polynomial kernel ek bade space mein ek dot product hai. 2D inputs , lo aur function

Step 1 — expand karo. Kyun? Hum dekhna chahte hain ki kya yeh ke roop mein factor hota hai.

Step 2 — dot product ke roop mein regroup karo. Kyun? Terms ko group karo taaki har summand (function of )(same function of ) ho.

Step 3 — padho. Kyun? Yeh ab literally hai jahan

Kab ek function ek valid kernel hai? Mercer's theorem ke anusaar: tabhi jab symmetric ho aur Gram matrix har dataset ke liye positive semidefinite ho. PSD guarantee karta hai ki koi feature map exist karti hai.

Figure — The kernel trick

Common kernels

RBF infinite-dimensional kyun hai? ko Taylor series ke roop mein expand karo: isme har degree ke polynomial terms hain. Har degree features add karti hai, isliye mein infinitely many features hain — explicitly compute karna impossible hai, kernel ke roop mein evaluate karna trivial hai. Isliye kernel trick sirf convenient nahi, balki essential hai.


Worked examples


Common mistakes (steel-manned)


Recall Feynman: ek 12 saal ke bachche ko samjhao

Socho tum ek circle ke andar red marbles aur bahar blue marbles ko alag karne ki koshish kar rahe ho, sab ek table par flat rakhe hain. Koi seedhi stick unhe split nahi kar sakti. Ab table ke beech ko pahad ki tarah upar uthao — reds oopar uthte hain, blues neeche rehte hain. Ab ek flat card unke beech slide kar sakta hai! Kernel trick ek jaadu ki ruler hai jo batata hai ki marbles uthane ke baad kitne door honge, bina kabhi pahad banaye. Tumhe answer free mein milta hai.


Recall

Kernel trick kya hai?
ko ek cheap function se compute karna bina high-dimensional feature map banaye.
Kernels ko SVM mein plug in kyun kar sakte hain?
Dual SVM aur uski prediction training points ko SIRF dot products ke through use karti hai, jise hum se replace karte hain.
2D mein ke liye feature map bolo.
.
Mercer's condition batao.
ek valid kernel hai tabhi jab woh symmetric ho aur uska Gram matrix har dataset ke liye positive semidefinite ho.
RBF kernel likho.
.
RBF feature space infinite-dimensional kyun hai?
Uska Taylor expansion har degree ke polynomial terms contain karta hai, jo infinitely many features add karta hai.
Bade ka RBF mein kya effect hota hai?
Similarity distance ke saath fast decay karti hai → har point isolated → overfitting / wiggly boundary.
Polynomial kernel formula aur uska feature-space size?
; size ka finite feature space.

Connections

  • Support Vector Machines — dual form jo dot products expose karta hai
  • Soft-margin SVM — jahan se aur aate hain
  • Mercer's Theorem — kernels ke liye validity condition
  • RBF Kernel — infinite-dimensional lift
  • Gaussian Naive Bayes — contrast: probabilistic vs margin-based
  • Overfitting and Regularization, tuning karna

Concept Map

motivates

becomes

explicit map costs

data appears only as

replace with

equals

avoided by

computed in

example

reveals

gives

predicts via

Non-linearly separable data

Lift to higher dimension

Linearly separable there

O n^d features expensive

Dual SVM form

Dot products x_i x_j

Kernel K x z

phi x dot phi z

Original space cheaply

Polynomial kernel x z squared

phi = x1^2, sqrt2 x1x2, x2^2

Nonlinear SVM for free

sign of sum alpha y K