Linear kernel measures similarity with a dot product, which only ever draws straight boundaries. The radial basis function (RBF) kernel, also called the Gaussian kernel, measures similarity by distance instead: two points that are close score near 1, and points far apart score near 0. A classifier built on it can carve out curved, island-shaped regions that no hyperplane could.
Given X with shape (n, d) and Y with shape (m, d), return the (n, m) matrix of RBF similarities with a width parameter gamma.
(n, m) where entry [i, j] equals exp(-gamma * ||X[i] - Y[j]||^2).gamma defaults to 1.0.rbf_kernel(X, X), which must be exactly 1 up to floating point error.X or Y.Open one at a time. Each gives away a little more than the last.
Squared distance expands as ||x||^2 + ||y||^2 - 2 x.y. That expansion gives the whole matrix from three pieces, with no double loop.
Floating point rounding can make a squared distance slightly negative for identical points, which would push exp above 1. Clip the squared distances at zero before exponentiating.
No results yet
Run your code to check it against the examples, or submit to run every test.