Kernel Trick
Lets a linear method draw curved boundaries by computing similarities as if the data lived in a higher-dimensional space, without ever building that space.
Also kernel function · RBF kernel · polynomial kernel · Gaussian kernel
Boser, Guyon and Vapnik, 1992
Dots in a ring around a center can't be split with a ruler. Lift each dot by how far it is from the center and a flat sheet separates them. The kernel trick gets that effect without doing the lifting.
Where it fits
+All relationships as a list
Is a kind of / part of
Applies to
Used by
How it works
Linear methods draw straight lines. To get curves, you could invent new features, for example add , and , and run the linear method on those. That is feature engineering, and it gets expensive fast: with many inputs the number of combinations explodes.
The kernel trick notices that some algorithms, notably support vector machines, never need the features themselves. They only need the dot product between pairs of examples, a measure of similarity. So replace that dot product with a kernel function that returns the similarity as if the points had been mapped to the bigger space.
The math
A kernel is a function . Common choices:
- Polynomial: , all feature products up to degree .
- RBF (Gaussian): . Its feature map is infinite-dimensional, yet each similarity costs one distance.
Any symmetric function whose similarity matrix is always positive semi-definite (Mercer’s condition) is a valid kernel.
The catch is scale: you need a similarity for every pair of training examples, so millions of examples become impractical. That limit is one reason neural networks, which learn their own features, took over on large datasets. The trick lives on in the wider kernel methods family.
Everyday use cases
- Case 01
Curved decision boundaries
An SVM with an RBF kernel separates classes that wrap around each other, such as a ring inside a ring.
- Case 02
Similarity on structured data
String and graph kernels compare DNA sequences or molecules directly, without hand-made features.
Strengths, weaknesses and when to use it
Strengths
- Nonlinear power from a linear algorithm, with the same convex optimization.
- Works on any data where you can define a valid similarity.
Weaknesses
- Needs a similarity for every pair of examples, so cost grows with the square of the dataset.
- Kernel choice and its width (γ) strongly affect results.
When to use itWhen a linear model underfits on a small to medium dataset and you want curved boundaries without a neural network.
Compare with
Check yourself
- Q01
What does the kernel trick avoid computing?
Show answer
B: The explicit coordinates of the points in the high-dimensional space
- Q02
Which algorithms can use the kernel trick?
Show answer
A: Any algorithm that uses the data only through dot products between examples