Nystrom Approximation and Random Fourier Features
Two tricks let kernel methods scale to large datasets by replacing an enormous exact similarity matrix with a small, cheap approximation that captures almost all of the same information.
Prerequisites: The Kernel Trick and Kernel Methods, Support Vector Machines
The kernel trick lets a model act as if it had transformed every data point into an infinite-dimensional space, just by computing similarity scores between pairs of points. The catch: with data points, that means an table of similarities. At 10,000 rows this is a hundred million numbers; at a million rows it is unusable — the table alone would not fit in memory, let alone the matrix algebra needed to train on it. Nystrom approximation and random Fourier features are two different ways of getting almost all of the kernel's benefit while touching only a small fraction of that table.
The analogy: you don't need every pairwise distance to draw the map
Imagine mapping every city in a country by recording the driving distance between every pair — millions of measurements for thousands of cities. A cheaper approach: pick a modest number of "landmark" cities, measure everyone's distance to just those landmarks, and reconstruct approximate positions for every other city from that. You lose a little precision but the measurement cost collapses from millions of pairs to a few thousand. That is the spirit of both techniques below — replace "compare every point to every point" with "compare every point to a small, well-chosen reference set."
Two routes to the same destination
Nystrom approximation picks landmark points (often a random sample), computes the full similarity of every point to just those landmarks, and uses that thin slice plus the small landmark-to-landmark block to reconstruct an approximation of the full kernel matrix. In symbols, if is the true kernel matrix, the approximation is
where is the slice (every point against every landmark) and is the landmark block. In plain English: rebuild the big similarity table from a thin strip of it, using the landmarks as a bridge between any two non-landmark points.
Random Fourier features takes a different route: instead of approximating the similarity matrix, it approximates the kernel function itself with a finite, explicit feature map. For kernels like the Gaussian (RBF) kernel, a classical result says the kernel can be written as an expectation over random sinusoids. Drawing random frequencies and building features gives an ordinary -dimensional vector such that — a plain dot product that approximates the kernel value. In plain English: instead of an implicit infinite-dimensional space, build a modest, explicit set of features and use a normal linear model on them.
Worked example 1: Nystrom on 6 points
Suppose points and we pick landmarks. The full kernel matrix would need entries. Nystrom only computes the entries of (every point to each landmark) plus the entries of — 16 numbers total, computed once, instead of 36, and the saving grows quadratically as grows while stays fixed. With and , Nystrom computes roughly million entries instead of million — a 50x reduction.
Worked example 2: random Fourier features on one point
Take (one feature), and draw random frequencies and offsets . Compute for each: , , , . Scale by : the feature vector is . Every point in the dataset gets its own such vector using the same random frequencies, and a plain linear model (or dot product) on these vectors approximates what the full kernel would have given — no matrix ever built.
Both methods trade an exact but unusably large kernel computation for a small, explicit approximation — Nystrom by sampling landmark points and reconstructing, random Fourier features by building a finite random feature map — so that a kernel method can train in time roughly linear in instead of quadratic or cubic.
What this means in practice
These approximations are what make kernel SVMs and Gaussian processes usable on datasets with tens or hundreds of thousands of rows, where the exact kernel matrix would never fit in memory. More landmarks or more random features buys accuracy at the cost of speed, so or is a knob a practitioner tunes directly against the compute budget.
It is tempting to think these methods just "speed up" the exact kernel method for free. They do not — they are genuine approximations, and a poorly chosen landmark set (Nystrom) or too few random frequencies (random Fourier features) can measurably hurt accuracy, especially near decision boundaries where precision matters most. Always check accuracy against a smaller exact-kernel baseline before trusting the approximation at scale.
Practice in interviews
Further reading
- Rahimi & Recht, Random Features for Large-Scale Kernel Machines (2007)
- Williams & Seeger, Using the Nystrom Method to Speed Up Kernel Machines (2001)