Kernel Methods
The kernel trick, the three kernels, and what degree and gamma actually do.
How to be non-linear without ever computing the non-linear map.
The problem: XOR
XOR is the canonical linearly non-separable problem: no single straight line separates $\{(0,0),(1,1)\}$ from $\{(0,1),(1,0)\}$.


The idea: map to a higher dimension
> Solution: there exists a mapping $\phi$ to a higher-dimensional space in which the data is linearly separable.
Suppose $x$ has 2 features. Map
$$\phi(x_1,x_2) = (x_1^2,\; x_2^2,\; \sqrt{2}x_1x_2)$$
and the classifier becomes
$$f(x) = w^T\phi(x) + b$$

For XOR this works because the product term $x_1x_2$ is negative in one class and positive in the other — a single threshold on it separates the classes.
Explicitly computing $\phi$ is expensive. For a degree-$d$ polynomial on $d$ features the mapped dimension grows combinatorially. This is the motivation sentence that must appear in any kernel-trick answer.
The kernel trick
> The dot product between two higher-dimensional mappings can be computed by a kernel function, without ever forming $\phi(x)$:
$$k(x,z) = \phi(x)^T\phi(z)$$

Because the SVM dual depends on the data only through inner products $\langle x_i, x_j\rangle$, you can replace every inner product with $k(x_i,x_j)$ and obtain a non-linear classifier at the cost of a linear one.
"What is the kernel trick? What is the purpose of a kernel function?" The SVM's dual formulation depends on training points only through inner products. The kernel trick replaces $\langle\phi(x),\phi(z)\rangle$ with a kernel $k(x,z)$ that computes that inner product implicitly, so a linear algorithm becomes non-linear without ever materialising the (possibly infinite-dimensional) feature map. The purpose is computational: the cost becomes one kernel evaluation per pair instead of an explicit high-dimensional expansion. The resulting decision function is $f(x)=\sum_i \alpha_i y_i k(x_i,x)+b$ — a weighted sum of similarities to the support vectors.
The three kernels — exact formulas


| Kernel | $k(x,z)$ | Hyperparameters and their role |
|---|---|---|
| Linear | $x^Tz$ | none (plus $C$) |
| Polynomial, degree $d$ | $(x^Tz)^d$ | $d$ — order of interaction; $d=1$ is linear |
| Polynomial, degree up to $d$ | $(x^Tz+1)^d$ | $d$ — includes all lower-order terms |
| RBF / Gaussian | $\exp\!\big(-\gamma\|x-z\|^2\big)$ | $\gamma$ — width of the influence of one point |
What $\gamma$ does — the deck shows it directly at $\gamma=0.1$ and $\gamma=1$:
- Small $\gamma$ — the kernel decays slowly, so every training point influences the prediction almost equally. The boundary is smooth, almost linear; risk of underfitting.
- Large $\gamma$ — the kernel decays fast, so each point only influences its own immediate neighbourhood. The boundary becomes tight and wiggly around individual points; risk of overfitting.
$\gamma$ behaves like the inverse of a radius: it is $1/(2\sigma^2)$ for a Gaussian of standard deviation $\sigma$.


What degree does — degree 2, 5 and 10 in sequence. Low degree underfits complex boundaries; high degree produces very flexible, high-variance boundaries and becomes numerically unstable.


"Name commonly used SVM kernels and discuss their hyperparameters." Linear $k(x,z)=x^Tz$ — no kernel hyperparameter; best when $d \gg N$ or the data is already separable. Polynomial $(x^Tz+1)^d$ — $d$ controls the order of feature interactions; larger $d$ = more flexible, more unstable. RBF $\exp(-\gamma\|x-z\|^2)$ — $\gamma$ sets the radius of influence, small $\gamma$ = smooth/underfit, large $\gamma$ = spiky/overfit. All three are combined with the margin-violation penalty $C$. Practical note: always scale features first, because the RBF kernel is a function of Euclidean distance.

























