← Explainer Library

Interactive Explainer

Kernel Methods, and Why DL Cares

Kernels never went away. The same recipe that powered SVMs underlies Gaussian processes, the Neural Tangent Kernel, and modern deep-kernel-learning hybrids. Click points and try four kernels live; then see the NTK and why the infinite-width-limit theory matters.

Step 1

The kernel trick in one line

A linear classifier learns $w$ such that $\mathrm{sign}(w^\top x)$ predicts the label. Replace $x \to \phi(x)$ for some feature map; the model becomes $\sum_i \alpha_i y_i \phi(x_i)^\top \phi(x) = \sum_i \alpha_i y_i k(x_i, x)$. You never need $\phi$ explicitly — only the kernel $k(x, x') = \phi(x)^\top \phi(x')$. That's the kernel trick.

Two consequences. First, the runtime depends on the number of training points $N$, not the (often infinite) feature dimension. Second, you can use kernels whose feature maps have no closed form — the RBF kernel $k(x, x') = \exp(-\|x-x'\|^2 / 2h^2)$ corresponds to an infinite-dimensional Gaussian feature map.

Step 1½

Mercer's theorem & what counts as a valid kernel

Not every symmetric function $k(x, x')$ is a kernel. The requirement: for any finite set of points $\{x_1, \dots, x_N\}$, the Gram matrix $K_{ij} = k(x_i, x_j)$ must be positive semi-definite. Mercer's theorem (1909) says such kernels admit a spectral decomposition

where $\{\lambda_i, \psi_i\}$ are eigenvalues and eigenfunctions of the integral operator $(T_k f)(x) = \int k(x, x') f(x') \, d\mu(x')$. The map $\phi(x) = (\sqrt{\lambda_i}\,\psi_i(x))_i$ is the implicit feature map you never had to compute. Two practical rules follow:

Step 1¾

The representer theorem

Why are all kernel-method solutions of the form $f^\star = \sum_i \alpha_i k(x_i, \cdot)$? The representer theorem (Kimeldorf & Wahba, 1971): for any loss $L$ depending only on $\{f(x_i)\}$ and any monotone regulariser $\Omega(\|f\|_\mathcal{H})$, the minimiser of

over the RKHS $\mathcal{H}$ associated with kernel $k$ lies in the finite-dimensional subspace $\mathrm{span}\{k(x_i, \cdot)\}_{i=1}^N$. So the infinite-dimensional variational problem reduces to an $N$-dimensional one in $\alpha$ — that's why kernel methods are tractable.

Step 2

Live: try four kernels

Click anywhere to drop a class-A (left-click) or class-B (right-click / shift-click) point. A kernel-ridge classifier re-fits each click and recolours the decision regions.

Left-click adds class-A (blue), right-click / shift-click adds class-B (orange). The boundary recomputes live.
Step 2½

Kernel design — pick the right symmetry

KernelFormulaImplicit feature mapUse when
Linear$x^\top x'$IdentityHigh-dim sparse data (text BoW)
Polynomial, deg $d$$(x^\top x' + c)^d$All monomials of degree $\le d$You expect feature interactions of bounded order
RBF / Gaussian$\exp(-\|x - x'\|^2 / 2h^2)$Infinite-dimSmooth signals, default
Laplacian$\exp(-\|x - x'\| / h)$Infinite-dim, rougherSparse signals, less smooth
Matérn-$\nu$tunable smoothness$\nu$-times differentiable functionsYou want to control smoothness exactly
Periodic$\exp(-2\sin^2(\pi\|x-x'\|/p)/h^2)$Fourier basisSeasonal time series
String / WL graphhistogram of subsequences / subtreescombinatorial featuresSequences, molecules, graphs

A practical rule of thumb: bandwidth $h$ ≈ median distance between points. The "median heuristic" is a strong default and the starting point for hyperparameter search. For the polynomial kernel, prefer the explicit feature expansion if you actually want feature interactions; for neural-net-like nonlinearities, prefer RBF or Matérn.

Step 2¾

The kernel-GP-SVM trinity

The same kernel gives you three different methods.

Mental model: kernel ridge = MAP GP. SVM = max-margin variant. Each adds a different ingredient (Bayesian posterior, sparsity) on top of the same kernel.

Step 3

NTK — the kernel inside an infinite-width net

A wide enough randomly-initialised neural net, when trained with vanishing learning rate, behaves as a kernel method (Jacot et al., 2018). Its kernel is the Neural Tangent Kernel:

For a 1-hidden-layer ReLU net the NTK has a known closed form. Below: a finite-width network's predictions alongside the analytic NTK regressor on the same training points. They agree better as you increase width.

Finite-width-net prediction (solid) vs NTK regressor (dashed). The gap shrinks as width →∞.
Why this matters. The NTK gives a rare-for-DL piece of theory: a closed-form prediction for what an over-parameterised network does. It has limits (real DL learns features; NTK does not), but it explains a lot of double-descent, generalisation, and optimisation behaviour seen in practice.
Step 3½

Scaling kernels past $N \approx 10^4$

The $O(N^3)$ fit and $O(N^2)$ memory of vanilla kernel methods stop being practical above ~10k points. Four standard escapes:

Step 3¾

Deep kernel learning

Why not the best of both worlds — let a neural net learn a feature map $\phi_\theta$ and feed that into a kernel?

Train $\theta$ jointly with the GP marginal likelihood (Wilson et al., 2016). The neural part learns representations; the GP part gives calibrated uncertainty. In 2024–2026 this is the default for tabular and small-data regression tasks where well-calibrated error bars matter — beats deep ensembles in head-to-head benchmarks on most small tabular regression datasets.

Step 4

Where kernel methods are still the right tool

Step 5

Practical gotchas

Step 6

Reading list