Part V — Non-Linear Models, Trees, Ensembles & Kernel Methods · Chapter 8

The kernel trick (RBF & Polynomial)

Hook

Last chapter's line found the widest possible street between two classes. What happens when there's no street at all — no line, at any angle, separates them?

Intuition
8/16 correct (50%) — try to beat it

One class rings the origin; the other rings that ring. Drag the line anywhere — there's always at least one point on the wrong side. This isn't a bad line; it's that no line can do better than about two-thirds here, because a straight cut can't tell "close to the center" from "far from it."

Formalize

The data isn't separable in (x,y)(x, y) — but it doesn't have to stay in (x,y)(x, y). Lift every point through one new feature, the squared distance from the origin:

z=x2+y2z = x^2 + y^2
  • zz — the new lifted feature: a point's squared distance from the origin.
  • xx, yy — the point's original two coordinates.
  1. Radius collapses points regardless of angle
    • Points near the center now share one small value of zz, no matter which direction they're in.
    • Points on the outer ring share one large value, no matter which direction they're in.
  2. Angle was the confusion, radius was the signal

    The two classes were tangled by angle but separated by radius all along — zz just throws away the angle and keeps the radius.

Play
z = 4.0 — 75% correct

This is the exact same 16 points, plotted by zz instead of (x,y)(x,y). One threshold now separates them completely — it's Chapter 7's split all over again, just on a feature that didn't exist until this chapter lifted it into being.

Worked example
  1. Transform an inner and an outer point
    • (1.8,0)(1.8, 0): z=1.82=3.24z = 1.8^2 = 3.24.
    • (4.7,0)(4.7, 0): z=4.72=22.09z = 4.7^2 = 22.09.
  2. Transform a diagonal point at the same inner radius

    (1.556,1.556)(1.556, 1.556): z=1.5562+1.55622.42+2.42=4.84z = 1.556^2 + 1.556^2 \approx 2.42+2.42 = 4.84 — the same value every inner point at that radius gets, regardless of angle.

  3. Confirm a single threshold separates everything
    • Every inner point lands with z4.84z \le 4.84.
    • Every outer point lands with z22.09z \ge 22.09.

    Any threshold in between — 10, 15, 20 — separates all sixteen points at once.

Checkpoint

Using the lifted feature — squared radius — drag the split until it separates every point: 100% accuracy.

z = 4.0 — 75% correct
Drag the split line to try it
Summary
z=x2+y2z = x^2 + y^2

This is the kernel trick's whole idea: a problem that's hopeless in the original features can become trivial in a cleverly chosen new one. Real kernels (polynomial, RBF — short for Radial Basis Function) do this implicitly, for far higher-dimensional lifts than one extra coordinate — but the shape of the win is exactly what you just saw: unseparable becomes separable, and the same one-threshold or widest-street machinery from the last two chapters still does the rest.