Learning path

Full curriculum

Full curriculum

Unit content

Kernel methods and the kernel trick

A linear model can become nonlinear in the original inputs if it is linear in a transformed feature representation $\phi(x)$.

For example,

$$\phi(x_1,x_2)=(x_1,x_2,x_1^2,x_1x_2,x_2^2)$$

allows a linear separator in feature space to represent a quadratic boundary in the original plane.

Some algorithms depend on transformed examples only through dot products $\phi(x)^T\phi(z)$. A kernel computes that dot product directly:

$$K(x,z)=\phi(x)^T\phi(z).$$

This is the kernel trick. It can avoid explicitly materializing a very high-dimensional feature vector.

A common example is the radial-basis-function kernel

$$K(x,z)=\exp(-\gamma|x-z|^2),$$

which assigns high similarity to nearby inputs.

Not every arbitrary similarity function is a valid kernel for standard kernel algorithms; it must correspond to an inner product in some feature space. Kernels let methods such as SVMs express nonlinear relationships while retaining optimization structures derived for linear models.