RBF Kernel

Easy
~12 min
code completion

Radial Basis Function (RBF) Kernel

Kernel SVMs implicitly map data to a higher-dimensional feature space using a kernel function — no explicit feature mapping needed.

The most popular kernel is the RBF (Gaussian) kernel:

Properties:

  • (a point is maximally similar to itself)
  • as
  • controls the kernel width — larger → tighter, more local kernel
  • Your task:

    Implement rbf_kernel(x1, x2, gamma) that returns the RBF kernel value between two vectors.

    Example Tests

    Identical points: K = 1.0

    Input: {"x1":[1,2],"x2":[1,2],"gamma":0.5}

    Expected: 1

    Unit distance, gamma=1: K = e^-1 ≈ 0.3679

    Input: {"x1":[0,0],"x2":[1,0],"gamma":1}

    Expected: 0.36788

    Larger gamma: faster decay

    Input: {"x1":[0,0],"x2":[1,0],"gamma":2}

    Expected: 0.13534

    Sign in to solve this problem

    You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.