The Kernel Trick: Why Inner Products Are All You Need
You are building a classifier. You decide to map your input to a high-dimensional (even infinite-dimensional) feature space , then run a linear classifier there.
The prediction function takes the form:
The puzzle: You never want to compute explicitly. Instead you only ever evaluate a kernel function .
Consider the polynomial kernel on , where .
(a) Find an explicit feature map such that .
(b) What is the dimension of the feature space? Now consider the more general kernel on . What is the dimension of the induced feature space as a function of and ? What happens as and grow?
(c) The conceptual punch line: Suppose evaluating costs time. Evaluating explicitly costs time, where grows polynomially in and . What does this say about the power of the kernel trick?
Answer: The Kernel Trick: Why Inner Products Are All You Need
Key Idea / Intuition
The kernel trick is the observation that many algorithms only need pairwise inner products between data points — never the feature vectors themselves. So if we can compute cheaply via a kernel function , we get the power of working in a huge (or infinite) feature space at the cost of working in the original space. The puzzle here is to make this concrete: expand the polynomial kernel by the binomial theorem and read off directly.
Formal Proof / Solution
Part (a): Explicit feature map for ,
Let and . Expand:
Apply the multinomial theorem:
This is exactly with:
Verification:
Part (b): Dimension of the feature space
For on :
The feature map consists of all monomials in the components of of degree , each with appropriate coefficients.
The number of monomials with is , so the total dimension is:
For fixed , this grows as ; for fixed , as .
Concretely:
- : ✓ (matches part (a))
- : — nearly 10 billion dimensions!
Part (c): The punch line
- Computing : costs — just a dot product and a power.
- Computing explicitly: costs , which is astronomically larger.
The kernel trick lets you implicitly operate in an -dimensional feature space while paying only per inner product.
More strikingly: for the RBF (Gaussian) kernel , the induced feature space is infinite-dimensional — yet you still evaluate in time. You are effectively running a linear classifier in -dimensional space at finite cost.
The key insight: Any algorithm (SVM, kernel regression, PCA, etc.) that only accesses data through inner products can be "kernelized" for free — the feature map need never be constructed explicitly. The computational bottleneck becomes the kernel matrix, not the dimension of the feature space.
Source: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman (2nd ed.), Ch. 12; also standard ML folklore