TensorTau PathToAGI Classical Machine Learning Level 04

Level 04 · Classical Machine Learning · Chapter 047

Kernels

If a straight boundary cannot separate the data, can we change the space so that a straight boundary becomes enough?

Where We Are

Support Vector Machines search for a separating hyperplane with a large margin. But XOR-like data cannot be separated by one line in its original coordinates.

We could create new features explicitly. Kernels give us a cleverer route.

1. Lift the data

Consider one-dimensional input xx. Add a feature x2x^2:

ϕ(x)=[x,x2].\phi(x)=[x,x^2].

Points that were tangled on a line can become separable in a plane.

original x:   • ○ ○ •

lifted (x,x²):
 x² ↑       •       •
    |    ○       ○
    +--------------→ x

A nonlinear boundary in the original space can be a linear boundary in the transformed space.

2. The computational problem

What if ϕ(x)\phi(x) contains millions—or infinitely many—features? Computing every coordinate sounds impossible.

The SVM optimization often needs feature vectors only through dot products:

ϕ(x)Tϕ(z).\phi(x)^T\phi(z).

A kernel computes that inner product directly:

K(x,z)=ϕ(x)Tϕ(z).K(x,z)=\phi(x)^T\phi(z).

This is the kernel trick.

3. Example: polynomial kernel

K(x,z)=(xTz+c)d.K(x,z)=(x^Tz+c)^d.

This behaves like a dot product in a feature space containing polynomial combinations, without explicitly constructing them all.

The RBF kernel is

K(x,z)=exp⁡(−γ∥x−z∥2).K(x,z)=\exp(-\gamma\lVert x-z\rVert^2).

Nearby points have similarity near 1; distant points approach 0.

4. A kernel is a similarity with geometry behind it

Do not memorize “kernel = magic nonlinear function.” The useful mental model is:

input points
   ↓ implicit feature map φ
richer space
   ↓ dot product
similarity used by a linear algorithm

5. The RBF scale matters

Large γ\gamma makes similarity decay very quickly. Each point influences only a tiny neighbourhood and the boundary can become wiggly.

Small γ\gamma creates broad influence and smoother boundaries.

This is another appearance of the complexity/generalization trade-off.

6. Beyond SVMs

Kernel ideas appear in Gaussian processes, kernel PCA, density methods and theoretical analyses. Modern neural networks usually learn representations rather than choose a fixed kernel, but both approaches share a central goal: create a geometry where the task becomes simpler.

What to Remember

  • Nonlinear data can become linearly separable after a feature transformation.
  • Kernels compute inner products in an implicit feature space.
  • Polynomial and RBF kernels create different geometries.
  • Hyperparameters control how flexible that geometry becomes.

Next → K-Means: so far labels told us what to predict. What can a machine discover when nobody gives it labels at all?

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

1 — Explain it

Explain the kernel trick using the idea of changing viewpoint rather than “adding magic dimensions.”

2 — Calculate it

For x=[1,2]x=[1,2], z=[2,1]z=[2,1], compute the degree-2 polynomial kernel (xTz+1)2(x^Tz+1)^2.

3 — Predict it

For an RBF kernel, predict what happens to similarity when distance doubles.

4 — Break it

Train an RBF SVM with extremely small and extremely large γ\gamma. Visualize both decision boundaries.

5 — Build it

Implement linear, polynomial and RBF kernel functions from scratch.

6 — Investigate it

On a two-moons dataset compare a linear SVM with RBF SVMs across several γ\gamma and CC values. Connect boundary shape to generalization.