2.4.4 · HinglishSVM, Naive Bayes & Probabilistic Models

Linear, polynomial, and RBF kernels

1,812 words8 min readRead in English

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


Kernels ki zaroorat KYUN hai?

Linear SVM KYA karta hai: yeh ek separating hyperplane dhundhta hai. Iska decision function, training ke baad, sirf dot products ke zariye likha ja sakta hai — query point aur support vectors ke beech:

Yeh KYUN matter karta hai: data sirf dot product ke andar aata hai. Toh agar data apni raw form mein linearly separable nahi hai, toh hum ise se ek richer space mein map kar sakte hain aur wahan separable hone ki umeed rakh sakte hain. Phir decision function ko chahiye hoga.

Trick humein KAISE bachati hai: explicitly compute karna expensive ya infinite-dimensional ho sakta hai. Lekin agar ek function ho jisme

toh hum kabhi nahi banate. Bas har dot product ko se replace kar dete hain. Yahi poora game hai.


Teen workhorse kernels

Yahan (gamma), (coef0), aur (degree) hyperparameters hain. Chaliye har ek ka feature map derive karte hain taki samajh aaye yeh valid KYUN hain.

1. Linear kernel — trivial map

Derivation. lo. Phir . Ho gaya. Yeh identity feature map ke saath ek kernel hai. Iska use tab karo jab bada ho aur data already ~linearly separable ho (text, sparse features).

2. Polynomial kernel — feature map scratch se derive karo

Sabse simple case lo: , , , 2D mein , .

Ise expand karo (yahi kyun yeh kernel hai — hum padh sakte hain):

Yeh step KYUN? Har term ko (kuch mein) (wahi kuch mein) ke roop mein group karo. Yahi grouping ek dot product hai jisme

Toh degree-2 polynomial kernel chupke se aapko saare squares, cross-terms aur linear terms deta hai — 2 inputs se ek 6-dimensional feature space, sirf ek dot product aur ek square se compute kiya gaya. control karta hai ki low-order terms ko kitna weight mile; bada → lower-degree features par zyada emphasis.

3. RBF kernel — yeh infinite-dimensional map KYUN hai

se shuru karo:

Ab last factor ko Taylor-expand karo:

Yeh step KYUN? Har khud degree ka ek (homogeneous) polynomial kernel hai, yaani ek finite space mein dot product. Kernels ka weighted sum bhi ek kernel hota hai, aur yahan sum infinity tak jaata hai → RBF ek infinite-dimensional feature map se correspond karta hai jisme har degree ke polynomial features hain. Isliye yeh itna expressive hai.

Figure — Linear, polynomial, and RBF kernels

Worked examples


Common mistakes (steel-manned)


Active recall

Recall Khud test karo (answers chhupao)
  • SVM ko sirf kyun chahiye, kyun nahi? → Decision function mein data sirf dot products ke andar aata hai.
  • Valid kernel ke liye Gram matrix mein kya property honi chahiye? → Symmetric positive semi-definite (Mercer).
  • RBF "infinite dimensional" KYUN hai? → ka Taylor expansion polynomial kernels ka ek infinite weighted sum hai.
  • RBF mein kya control karta hai? → Har point ki reach/locality; bias–variance tradeoff.

Flashcards

Kernel trick kya hai?
Har dot product ko algorithm mein se replace karna, ek high-dim feature space gain karna bina compute kiye.
Linear kernel ka formula?
, feature map ke saath.
Polynomial kernel ka formula?
.
RBF/Gaussian kernel ka formula?
.
Kaunsi condition kisi function ko valid kernel banati hai?
Iska Gram matrix symmetric positive semi-definite hona chahiye (Mercer's theorem).
2D mein degree-2 poly kernel ka feature map?
.
RBF infinite-dimensional KYUN hai?
Kyunki har degree ke polynomial kernels ko mix karta hai.
RBF mein bade ka effect?
Bahut local influence → wiggly boundary → overfitting ka risk.
RBF mein chote ka effect?
Smooth, near-linear boundary → underfitting ka risk.
Linear kernel kab prefer karo?
High-dimensional sparse data (text) jahan nonlinearity overfit kare; speed ke liye bhi.
RBF/poly se pehle features scale KYUN karne chahiye?
Yeh / par depend karte hain, jo large-magnitude features se dominate hote hain.

Recall Feynman: ek 12-saal ke bachche ko samjhao

Socho tum do khilaunon ki "alikeness" judge kar rahe ho. Linear tarika: unhe line up karo aur dekho kitna same direction mein point karte hain. Polynomial tarika: unke combinations bhi compare karo — colour AUR size saath mein, sirf akela nahi. RBF tarika: bas measure karo kitne paas hain — touching khilaune "1" hain, door wale "0" hain. Jaadu ki baat yeh hai ki computer yeh alikeness seedha measure kar sakta hai, bina har possible combination ki giant table banaye. Yeh shortcut SVM ko groups ke beech curved fences draw karne deta hai, jabki sirf simple arithmetic karta hai.

Connections

  • Support Vector Machines — kernels dual decision function mein plug hote hain.
  • The Kernel Trick — teeno ke peeche ka general principle.
  • Mercer's Theorem — PSD Gram matrix condition.
  • Bias-Variance Tradeoff, , aur ise control karte hain.
  • Feature Scaling / Standardization — required preprocessing.
  • Overfitting and Regularization — complexity kyun nahi badhani chahiye.
  • Gaussian / RBF functions — Naive Bayes densities jaisi same bell shape.

Concept Map

decision uses only

map data with

needs

expensive to build

replaces dot product with

equals

valid if

type

type

type

phi is identity

expands to

form

Linear SVM hyperplane

Dot products of points

Feature map phi

Higher-dim space

Kernel trick

Kernel K x,z

phi x dot phi z

Mercer PSD Gram matrix

Linear kernel

Polynomial kernel

RBF Gaussian kernel

Squares and cross-terms