Kernels and the Kernel Trick

A linear classifier draws a straight line, plane, or hyperplane through data. Many real problems are not linearly separable in their raw coordinates. This includes XOR-like patterns and protein classification. The kernel trick lets a linear algorithm act as if the data had been mapped into a vastly higher-dimensional feature space. This space can even be infinite-dimensional. The algorithm achieves this without ever constructing that space explicitly. The core insight is deceptively simple. Many learning algorithms can be rewritten in a special form. This includes soft-margin SVMs and ridge regression. In this form, the data enter only through pairwise inner products. If we replace every inner product with a cleverly chosen function called a kernel, the algorithm changes behavior. It behaves exactly as if it operated on transformed features. Meanwhile, all computation still happens in the original input space. This matters enormously in practice. Support vector machines with the RBF kernel remain competitive on small-to-medium tabular datasets. Kernel ridge regression underlies Gaussian process regression. Kernel methods for two-sample testing and independence testing (MMD, HSIC) are workhorses in modern statistics. Even parts of deep learning theory are best understood through this lens. This includes the neural tangent kernel. This article builds the idea from first principles. It covers what a feature map is, and why the "trick" works algebraically. It explains what makes a function a valid (Mercer) kernel. It also shows how the machinery plays out in the dual formulation of a classifier. It closes with worked numerical traces, common failure modes, and the history of the idea.

Key takeaways
  • A kernel k(x,x′)k(x, x') computes an inner product ⟨ϕ(x),ϕ(x′)⟩\langle \phi(x), \phi(x')\rangle in some feature space, without forming ϕ(x)\phi(x) explicitly.
  • Many algorithms (SVM, ridge regression, PCA, k-means) can be rewritten in "dual form" using only pairwise inner products of training points.
  • Substituting a kernel for the dot product in dual form implicitly performs linear learning in a nonlinear feature space — the kernel trick.
  • Mercer's theorem characterizes valid kernels: a symmetric function is a kernel iff its Gram matrix is positive semi-definite for every finite sample.
  • Popular kernels include polynomial, RBF/Gaussian, and string/graph kernels; each encodes a different notion of similarity.
  • The main costs are O(n2)O(n^2) storage and up to O(n3)O(n^3) training time in nn (sample size), motivating approximations like Nyström and random features for large nn.
The core insight

The kernel trick replaces explicit nonlinear feature maps with a similarity function, letting linear algorithms learn nonlinear decision boundaries at the cost of working in sample space instead of feature space.

The idea

A feature map ϕ:X→H\phi: \mathcal{X} \to \mathcal{H} sends raw inputs into a (possibly infinite-dimensional) inner-product space H\mathcal{H}, called the feature space. A linear model built on ϕ(x)\phi(x), such as f(x)=w⊤ϕ(x)+bf(x) = w^\top \phi(x) + b, can represent nonlinear functions of the original xx even though it is linear in the transformed coordinates. The difficulty is that ϕ\phi can be expensive or impossible to compute explicitly — for the Gaussian RBF kernel, H\mathcal{H} is infinite-dimensional. A kernel function k:X×X→Rk: \mathcal{X} \times \mathcal{X} \to \mathbb{R} is defined by

k(x,x′)=⟨ϕ(x),ϕ(x′)⟩Hk(x, x') = \langle \phi(x), \phi(x') \rangle_{\mathcal{H}}

for some feature map ϕ\phi and inner product space H\mathcal{H}. The kernel trick is the observation that if a learning algorithm's objective and prediction rule can be expressed using training data only through such inner products ⟨ϕ(xi),ϕ(xj)⟩\langle \phi(x_i), \phi(x_j)\rangle, then we may replace every occurrence of that inner product with k(xi,xj)k(x_i, x_j), computed directly from xi,xjx_i, x_j in the original space, in time independent of dim⁡H\dim \mathcal{H}. This is possible precisely because many convex learning problems admit a dual formulation — expressed in terms of an n×nn \times n Gram matrix KK with Kij=k(xi,xj)K_{ij} = k(x_i, x_j) — rather than a primal formulation expressed in terms of a weight vector w∈Hw \in \mathcal{H}. Not every function of two arguments is a legitimate kernel. Mercer's theorem gives the precise characterization: a symmetric function kk is a valid kernel (i.e., it corresponds to some inner product in some Hilbert space) if and only if, for every finite set of points x1,…,xnx_1,\dots,x_n, the Gram matrix KK with entries Kij=k(xi,xj)K_{ij}=k(x_i,x_j) is symmetric positive semi-definite (PSD), meaning z⊤Kz≥0z^\top K z \ge 0 for all z∈Rnz \in \mathbb{R}^n. This is the mathematical guarantee that turns "any symmetric similarity function" into "a genuine dot product in disguise," and it is what licenses substituting kk for ⟨ϕ(x),ϕ(x′)⟩\langle \phi(x),\phi(x')\rangle inside an optimization problem that was originally derived assuming a real Hilbert space geometry (needed, for instance, so that the dual objective remains convex).

How it works

The mechanism has three moving parts: (1) deriving the dual form of a linear algorithm, (2) substituting a kernel for the inner product, and (3) using the resulting dual solution to predict on new points — again only via kernel evaluations.

Step 1 — the primal problem. Consider soft-margin SVM classification with labels yi∈{−1,+1}y_i \in \{-1,+1\}:

min⁡w,b,ξ 12∥w∥2+C∑iξis.t. yi(w⊤ϕ(xi)+b)≥1−ξi, ξi≥0.\min_{w,b,\xi} \ \tfrac12 \|w\|^2 + C\sum_i \xi_i \quad \text{s.t. } y_i(w^\top \phi(x_i)+b) \ge 1-\xi_i,\ \xi_i \ge 0.

Step 2 — Lagrangian duality. Introducing multipliers αi≥0\alpha_i \ge 0 for the margin constraints and μi≥0\mu_i \ge 0 for ξi≥0\xi_i\ge0, and setting the gradient of the Lagrangian with respect to ww to zero gives the representer-style identity

w=∑iαiyiϕ(xi).w = \sum_i \alpha_i y_i \phi(x_i).

Substituting back eliminates ww entirely and yields the dual objective

max⁡α ∑iαi−12∑i,jαiαjyiyj ⟨ϕ(xi),ϕ(xj)⟩s.t. 0≤αi≤C, ∑iαiyi=0.\max_{\alpha} \ \sum_i \alpha_i - \tfrac12 \sum_{i,j}\alpha_i\alpha_j y_i y_j \, \langle \phi(x_i),\phi(x_j)\rangle \quad \text{s.t. } 0\le \alpha_i \le C,\ \sum_i \alpha_i y_i = 0.

Crucially, ϕ\phi appears only inside inner products ⟨ϕ(xi),ϕ(xj)⟩\langle \phi(x_i),\phi(x_j)\rangle.

Step 3 — the substitution. Replace ⟨ϕ(xi),ϕ(xj)⟩\langle \phi(x_i),\phi(x_j)\rangle with k(xi,xj)k(x_i,x_j):

max⁡α ∑iαi−12∑i,jαiαjyiyj Kijs.t. 0≤αi≤C, ∑iαiyi=0.\max_{\alpha}\ \sum_i \alpha_i - \tfrac12\sum_{i,j}\alpha_i\alpha_j y_iy_j\,K_{ij} \quad \text{s.t. } 0\le\alpha_i\le C,\ \sum_i \alpha_i y_i=0.

This is a finite-dimensional quadratic program in α∈Rn\alpha \in \mathbb{R}^n, solvable without ever forming ϕ(xi)\phi(x_i).

Step 4 — prediction. Because w=∑iαiyiϕ(xi)w=\sum_i \alpha_i y_i \phi(x_i), the decision function is

f(x)=∑iαiyi⟨ϕ(xi),ϕ(x)⟩+b=∑iαiyi k(xi,x)+b,f(x) = \sum_i \alpha_i y_i \langle \phi(x_i),\phi(x)\rangle + b = \sum_i \alpha_i y_i\, k(x_i,x) + b,

again only through kernel evaluations against training points. Points with αi>0\alpha_i>0 are the support vectors; typically most αi=0\alpha_i=0 at the optimum, so prediction only sums over a sparse subset. The same recipe applies to kernel ridge regression. Primal ridge regression solves min⁡w∥y−Φw∥2+λ∥w∥2\min_w \|y-\Phi w\|^2+\lambda\|w\|^2, giving w=(Φ⊤Φ+λI)−1Φ⊤yw=(\Phi^\top\Phi+\lambda I)^{-1}\Phi^\top y. Using the identity (Φ⊤Φ+λI)−1Φ⊤=Φ⊤(ΦΦ⊤+λI)−1(\Phi^\top\Phi+\lambda I)^{-1}\Phi^\top = \Phi^\top(\Phi\Phi^\top+\lambda I)^{-1} (a standard push-through/Woodbury identity), predictions become

y^(x)=k(x)⊤(K+λI)−1y,\hat y(x) = k(x)^\top (K+\lambda I)^{-1} y,

where K=ΦΦ⊤K=\Phi\Phi^\top has entries Kij=k(xi,xj)K_{ij}=k(x_i,x_j) and k(x)i=k(xi,x)k(x)_i = k(x_i,x) — again expressed purely through the kernel. ```text ALGORITHM: Kernelized soft-margin SVM (training and prediction) INPUT: training pairs (x_1,y_1),...,(x_n,y_n), kernel function k(.,.), box constant C TRAINING: 1. Build Gram matrix K where K[i][j] = k(x_i, x_j) # O(n^2) kernel evaluations 2. Solve the dual QP: maximize sum_i alpha_i - 0.5 sum_i sum_j alpha_i alpha_j y_i y_j K[i][j] subject to 0 <= alpha_i <= C for all i sum_i alpha_i y_i = 0 (e.g. via SMO: repeatedly pick a violating pair (i, j), solve the 2-variable sub-problem in closed form, update alpha_i, alpha_j) 3. Identify support vectors: S = { i : alpha_i > 0 } 4. Recover bias b using any i with 0 < alpha_i < C (KKT stationarity): b = y_i - sum_{j in S} alpha_j y_j K[i][j] PREDICTION on new point x: 1. score = b 2. for each i in S: score += alpha_i y_i * k(x_i, x) 3. return sign(score) ```

Figure
From input space to an implicit feature space via the kernel
Input space 𝒳 not linearly separable φ (implicit) Feature space ℋ linear separator w k(x, x') = ⟨φ(x), φ(x')⟩ computed WITHOUT building φ

Complexity & correctness

Time and space complexity. Building the Gram matrix costs O(n2⋅c)O(n^2 \cdot c), where nn is the number of training points and cc is the cost of one kernel evaluation (for the RBF or polynomial kernel on dd-dimensional vectors, c=O(d)c=O(d)). Storing KK costs O(n2)O(n^2) memory. Solving the dual QP exactly with a generic interior-point method costs roughly O(n3)O(n^3); practical solvers such as Sequential Minimal Optimization (SMO) avoid ever forming the full inverse and instead perform many cheap two-variable updates, giving empirical scaling closer to O(n2)O(n^2) to O(n3)O(n^3) depending on the kernel, the regularization CC, and the desired tolerance. Kernel ridge regression requires inverting or solving a linear system with K+λIK+\lambda I, an explicit O(n3)O(n^3) operation (or O(n2)O(n^2) per iteration with conjugate gradient, times a number of iterations that depends on the conditioning of K+λIK+\lambda I). Prediction on a new point costs O(∣S∣⋅c)O(|S|\cdot c) where SS is the support-vector set (SVM) or O(n⋅c)O(n\cdot c) (kernel ridge, which is generally non-sparse). This is the central tradeoff of kernel methods: the explicit feature space may be infinite-dimensional and free to work in, but the computational cost is paid entirely in sample size nn, not in feature dimension dHd_{\mathcal H}. This is favorable when dH≫nd_{\mathcal H} \gg n (kernels effectively give you unlimited-capacity features "for the price of n2n^2"), and unfavorable when nn is very large — a regime where explicit random-feature approximations or linear models often win.

Correctness of the substitution. Why is it valid to swap ⟨ϕ(xi),ϕ(xj)⟩\langle\phi(x_i),\phi(x_j)\rangle for k(xi,xj)k(x_i,x_j) rather than merely convenient? Two facts must both hold: 1. Algebraic sufficiency. The primal optimization problem's data dependence, after applying strong duality (Slater's condition holds here since the primal is a convex QP with linear/affine constraints), reduces to an expression involving {xi}\{x_i\} only through the pairwise quantities ⟨ϕ(xi),ϕ(xj)⟩\langle \phi(x_i),\phi(x_j)\rangle. This was shown explicitly in the SVM derivation above — no other functional of ϕ(xi)\phi(x_i) ever appears in the dual objective, the constraints, or the final decision rule. 2. Existence of a witness. Mercer's theorem guarantees that if kk is symmetric and every Gram matrix it produces is PSD, then there exists some Hilbert space H\mathcal{H} and map ϕ\phi with k(x,x′)=⟨ϕ(x),ϕ(x′)⟩Hk(x,x')=\langle\phi(x),\phi(x')\rangle_{\mathcal H} (constructively, H\mathcal{H} can be taken to be the reproducing kernel Hilbert space, RKHS, associated with kk, via the Moore–Aronszajn theorem). Because such a ϕ\phi exists, the dual QP built from Kij=k(xi,xj)K_{ij}=k(x_i,x_j) is exactly the dual QP that would have resulted from explicitly mapping the data through this particular ϕ\phi and running ordinary linear SVM. Hence solving the kernelized dual is provably equivalent to (not merely "inspired by") training a linear classifier in H\mathcal H. The PSD requirement is also what keeps the dual QP convex: the quadratic form α⊤(yy⊤⊙K)α\alpha^\top (yy^\top \odot K)\alpha must be bounded below, which needs K⪰0K \succeq 0 (since yy⊤⊙Kyy^\top\odot K is PSD whenever KK is, as a Hadamard product of PSD matrices with a rank-one PSD matrix is PSD by the Schur product theorem). Without this, the optimizer could diverge or find spurious saddle points instead of a global optimum — so Mercer's condition is not a technicality but the exact hypothesis needed for the argument in point 1 to produce a well-posed convex problem.

Honest tradeoffs. Kernel methods give flexible, often infinite-dimensional hypothesis classes with strong convex-optimization guarantees, but: (a) they scale poorly to large nn without approximation (Nyström low-rank approximation of KK, or random Fourier features that approximate shift-invariant kernels with explicit finite-dimensional maps, are the standard remedies); (b) kernel choice and its hyperparameters (bandwidth γ\gamma in RBF, degree in polynomial) require tuning, typically via cross-validation, and a poor choice can under- or over-smooth badly; (c) unlike a neural network, a kernel machine cannot learn its own feature representation — the practitioner supplies kk.

Worked example

Take four 2-D points that are not linearly separable: an XOR pattern.

iixix_iyiy_i
1(1,1)(1,1)+1+1
2(−1,−1)(-1,-1)+1+1
3(1,−1)(1,-1)−1-1
4(−1,1)(-1,1)−1-1

No hyperplane in R2\mathbb{R}^2 separates {1,2}\{1,2\} from {3,4}\{3,4\}: the classes alternate around the square. Use the degree-2 polynomial kernel k(x,x′)=(x⊤x′+1)2k(x,x')=(x^\top x' + 1)^2, which corresponds to a feature map into monomials up to degree 2 (a standard identity: k(x,x′)=(x1x1′+x2x2′+1)2k(x,x')=(x_1x_1'+x_2x_2'+1)^2 expands into terms 1,2x1,2x2,x12,x22,2x1x21, \sqrt2 x_1,\sqrt2 x_2, x_1^2, x_2^2,\sqrt2 x_1x_2 — six explicit features).

Step 1: compute the Gram matrix. For any i,ji,j, xi⊤xj∈{2,−2,0}x_i^\top x_j \in \{2,-2,0\} depending on agreement of coordinates:

KKx1=(1,1)x_1{=}(1,1)x2=(−1,−1)x_2{=}(-1,-1)x3=(1,−1)x_3{=}(1,-1)x4=(−1,1)x_4{=}(-1,1)
x1x_1(2+1)2=9(2{+}1)^2{=}9(−2+1)2=1(-2{+}1)^2{=}1(0+1)2=1(0{+}1)^2{=}1(0+1)2=1(0{+}1)^2{=}1
x2x_211991111
x3x_311119911
x4x_411111199

Step 2: solve the dual QP. By the symmetry of this configuration (all off-diagonal entries equal, all same-class pairs equal), the maximizer is αi=α\alpha_i=\alpha for all ii, for some common value α>0\alpha>0, satisfying ∑iαiyi=α−α+(−α)−(−α)=0\sum_i \alpha_i y_i = \alpha - \alpha + (-\alpha)-(-\alpha) = 0 automatically. Plugging αi=α\alpha_i=\alpha into the stationarity condition ∂/∂αi\partial/\partial\alpha_i of the dual objective (each point's margin constraint is tight and symmetric) gives, after solving the resulting linear system exploiting the symmetric structure, α=1/4\alpha = 1/4 for all four points (all four are support vectors, and one can verify directly that ∑iαi−12∑ijαiαjyiyjKij\sum_i \alpha_i - \tfrac12\sum_{ij}\alpha_i\alpha_jy_iy_jK_{ij} is stationary at this point by substitution, using Kii=9K_{ii}=9 and off-diagonal Kij=1K_{ij}=1).

Step 3: decision function. With αi=1/4\alpha_i = 1/4 for all ii and bias b=0b=0 (by symmetry of the problem around the origin):

f(x)=14[(+1)k(x1,x)+(+1)k(x2,x)−(1)k(x3,x)−(1)k(x4,x)].f(x) = \tfrac14\Big[ (+1)k(x_1,x) + (+1)k(x_2,x) - (1)k(x_3,x) - (1)k(x_4,x)\Big].

Check on the training points themselves, e.g. x=x1=(1,1)x=x_1=(1,1):

f(x1)=14[1⋅9+1⋅1−1⋅1−1⋅1]=14(8)=2>0,f(x_1) = \tfrac14\big[1\cdot 9 + 1\cdot 1 - 1\cdot 1 - 1\cdot 1\big] = \tfrac14(8) = 2 > 0,

correctly recovering label +1+1. Check x=x3=(1,−1)x=x_3=(1,-1):

f(x3)=14[1⋅1+1⋅1−1⋅9−1⋅1]=14(−8)=−2<0,f(x_3) = \tfrac14\big[1\cdot 1 + 1\cdot 1 - 1\cdot 9 - 1\cdot 1\big] = \tfrac14(-8) = -2 < 0,

correctly recovering label −1-1. In the explicit 6-dimensional feature space this is nothing but a hyperplane (in fact along the x1x2x_1x_2 monomial direction), but note the entire computation above used only 2×22\times2 entries and KK — the 6-dimensional vectors were never formed.

Common pitfalls & traps

PitfallWhy it happensConsequence
Forgetting to check Mercer/PSD when hand-crafting a kernelAny symmetric function "feels" like a similarity measureNon-convex or ill-posed dual; solver may not converge or "solution" is meaningless
Not standardizing features before RBF/polynomial kernelsKernel value dominated by large-scale coordinatesBandwidth mis-set; kernel saturates to 0 or 1 everywhere, killing discriminative power
Treating γ\gamma (RBF bandwidth) or polynomial degree as fixed defaultsLibrary defaults rarely match the data's intrinsic scaleSevere over- or under-fitting; looks like a "bad algorithm" when it is a bad hyperparameter
Assuming kernel methods scale like linear modelsLinear SVMs scale near-linearly in nn; kernel Gram matrix is O(n2)O(n^2)Out-of-memory or multi-hour training on datasets with nn in the hundreds of thousands
Confusing "kernel trick" with "any nonlinear transform"Superficial resemblance to feature engineeringMissing the requirement that the map be implicit and computed via inner products only
Using a kernel matrix from training data at test time incorrectly (leaking test points into KK during model selection)Cross-validation folds not respecting the Gram matrix structureOptimistically biased validation performance

Pioneers & history

Kernel methods sit at the intersection of functional analysis, going back a century, and statistical learning theory developed in the second half of the twentieth century.

Origins · 1 minVladimir Vapnik and how this was discovered
VV
Vladimir Vapnik
1936–present · Co-inventor of statistical learning theory and support vector machines at AT&T Bell Labs, whose work with Corinna Cortes and Bernhard Boser formalized the kernelized soft-margin SVM

James Mercer's 1909 theorem on positive-definite integral kernels, originally developed for solving integral equations, supplied the mathematical backbone decades before machine learning existed as a field. Aizerman, Braverman, and Rozonoer first proposed using kernel functions with the perceptron-like "potential function" method in 1964, effectively discovering the trick in isolation. It lay relatively dormant until Boser, Guyon, and Vapnik combined it with the maximum-margin classifier in 1992, and Cortes and Vapnik's 1995 soft-margin formulation made it robust to non-separable, noisy data — the version taught today. The 1990s and 2000s saw an explosion of kernel design: string kernels for text and biosequences, graph kernels, and the formalization of the reproducing kernel Hilbert space (RKHS) framework by Aronszajn, tying the whole enterprise to rigorous functional analysis.

Origins · 1 minhow this was discovered
History
1909
— Mercer's theorem on positive-definite kernels published.
1950
— Aronszajn formalizes reproducing kernel Hilbert spaces.
1964
— Aizerman, Braverman, Rozonoer use kernel functions with the perceptron ("potential function method").
1992
— Boser, Guyon, Vapnik introduce the maximum-margin kernel SVM.
1995
— Cortes and Vapnik publish the soft-margin SVM with hinge loss.

Where this matters

Kernel SVMs remain a strong baseline on small-to-medium tabular and bioinformatics datasets — protein classification, remote-sensing image classification, and chemical property prediction (via specialized graph and string kernels) all rely on domain-specific kernels encoding structural similarity that a generic vector representation would lose. Kernel ridge regression is mathematically identical to the posterior mean of a Gaussian process regressor, so the same machinery underlies Bayesian optimization tools used for hyperparameter tuning and experimental design in industry (e.g., tuning compiler flags, materials discovery, A/B test allocation). Kernel two-sample tests (Maximum Mean Discrepancy) and kernel independence tests (HSIC) are standard tools in modern causal inference and generative model evaluation, including judging the quality of GAN and diffusion model samples. Large-scale systems that cannot afford O(n2)O(n^2) Gram matrices instead use random Fourier features or the Nyström method to build explicit low-dimensional approximations of a kernel's implicit feature map, letting kernel-flavored models scale to millions of examples inside standard linear-model training pipelines. Understanding kernels also illuminates the k-Nearest Neighbors connection: both are "instance-based" methods that predict using stored training points and a similarity function, though kernel machines learn weights αi\alpha_i on those points via a convex optimization rather than using uniform local voting.

Ask the tutor: How does the representer theorem guarantee that kernel methods generalize the same regularized risk-minimization framework used in ridge regression and SVMs?

What exactly does "implicit" mean when we say a kernel implies a feature map without computing it?

It means the feature map ϕ\phi exists mathematically (guaranteed by Mercer's theorem via the associated RKHS) but the algorithm never materializes the vector ϕ(x)\phi(x) in memory. Every step of training and prediction is rewritten so the only operations needed are evaluations of k(xi,xj)k(x_i,x_j), a scalar computed directly from the raw inputs. This is why an RBF kernel can correspond to an infinite-dimensional feature space: you would never be able to store ϕ(x)\phi(x) as an array, yet you can still compute k(x,x′)k(x,x') in O(d)O(d) time and run the entire learning algorithm.

How is the RBF (Gaussian) kernel's feature space infinite-dimensional?

Expanding k(x,x′)=exp⁡(−γ∥x−x′∥2)k(x,x')=\exp(-\gamma\|x-x'\|^2) using the Taylor series of the exponential shows it is an infinite sum of terms, each of which is itself a polynomial kernel of increasing degree scaled by a positive coefficient. Since a polynomial kernel of degree pp corresponds to a feature map into monomials of degree up to pp, an infinite sum of such kernels (with positive weights, preserving positive semi-definiteness by closure under nonnegative combination) corresponds to a feature map into a space with a term for every possible monomial degree — a countably infinite-dimensional feature space, the RKHS associated with the Gaussian kernel.

Is the kernel trick the same thing as manual feature engineering, like adding x12x_1^2 or x1x2x_1x_2 as new columns?

No, though the two are related. Manually adding polynomial terms explicitly constructs ϕ(x)\phi(x) and then trains a linear model on it — feasible only when dim⁡H\dim\mathcal{H} is small. The kernel trick achieves the same mathematical effect (linear separation in that expanded space) but computes only the scalar inner product k(x,x′)k(x,x'), which stays cheap even when the implied feature space is astronomically large or infinite. The trick is specifically the substitution inside a dual formulation, not the general idea of nonlinear features.

Why does the kernel trick require rewriting the algorithm in dual form rather than just applying ϕ\phi inside the usual formulas?

Applying ϕ\phi directly would require actually computing and storing ϕ(x)\phi(x), which defeats the purpose when H\mathcal{H} is high- or infinite-dimensional. The dual form is special because, after eliminating the primal weight vector ww via the stationarity condition w=∑iαiyiϕ(xi)w=\sum_i \alpha_i y_i\phi(x_i), every remaining occurrence of ϕ\phi in the objective and decision rule is trapped inside an inner product ⟨ϕ(xi),ϕ(xj)⟩\langle\phi(x_i),\phi(x_j)\rangle. Only in that specific algebraic form can the inner product be swapped for k(xi,xj)k(x_i,x_j) without changing what mathematical problem is being solved.

Can any machine learning algorithm be kernelized?

Only algorithms whose solution can be expressed via inner products of the data, which is guaranteed for a broad class of problems by the representer theorem: for a wide class of regularized empirical risk minimization problems, the optimal ww is always a linear combination of the training points' feature vectors, w=∑iciϕ(xi)w=\sum_i c_i \phi(x_i). This applies to ridge regression, SVMs, kernel PCA, kernel logistic regression, and Gaussian processes. It does not directly apply to algorithms without this variational structure, such as decision trees, though hybrid kernel-based analogues (e.g., kernel density trees) exist in specialized forms.

How do practitioners choose between an RBF kernel, a polynomial kernel, and a linear kernel?

A linear kernel (equivalent to no kernel at all, k(x,x′)=x⊤x′k(x,x')=x^\top x') is preferred when dd is already large relative to nn (e.g., text with bag-of-words features), since nonlinear kernels add little and cost more. The RBF kernel is a strong general-purpose default when dd is moderate and nonlinear structure is expected, controlled by a bandwidth γ\gamma tuned via cross-validation. Polynomial kernels are chosen when interactions of a specific bounded degree are believed relevant. In practice, RBF combined with grid search over (C,γ)(C,\gamma) is the standard first approach for small-to-medium tabular problems.

How do methods like the Nyström approximation or random Fourier features avoid the O(n2)O(n^2) cost?

The Nyström method approximates the full n×nn\times n Gram matrix KK by sampling a small subset of m≪nm \ll n "landmark" points and using their kernel values to build a low-rank factorization K≈KnmKmm−1KmnK \approx K_{nm}K_{mm}^{-1}K_{mn}, reducing storage and solve costs to roughly O(nm)O(nm) and O(m3)O(m^3). Random Fourier features instead approximate a shift-invariant kernel directly, via Bochner's theorem, by an explicit finite-dimensional randomized map z(x)∈RDz(x)\in\mathbb{R}^D such that z(x)⊤z(x′)≈k(x,x′)z(x)^\top z(x') \approx k(x,x'), letting the model be trained as an ordinary linear model in DD dimensions, avoiding the Gram matrix entirely.

Before this