The RBF Kernel
Introduction:
RBF short for Radial Basis Function Kernel is a very powerful kernel used in SVM. Unlike linear or
polynomial kernels, RBF is more complex and efficient at the same time that it can combine multiple
polynomial kernels multiple times of different degrees to project the non-linearly separable data into
higher dimensional space so that it can be separable using a hyperplane.
Formula:
The RBF kernel works by mapping the data into a high-dimensional space by finding the dot products
and squares of all the features in the dataset and then performing the classification using the basic idea
of Linear SVM. For projecting the data into a higher dimensional space, the RBF kernel uses the so-called
radial basis function which can be written as:
Here ||X1 - X2||^2 is known as the Squared Euclidean Distance and σ is a free parameter that can be
used to tune the equation. The equation is really simple here, the Squared Euclidean Distance is
multiplied by the gamma parameter and then finding the exponent of the whole. This equation can find
the transformed inner products for mapping the data into higher dimensions directly without actually
transforming the entire dataset which leads to inefficiency. And this is why it is known as the RBF kernel
function
Distribution Graph:
As you can see that the Distribution graph of the RBF kernel actually looks like the Gaussian Distribution
curve which is known as a bell-shaped curve. Thus RBF kernel is also known as Gaussian Radial Basis
Kernel.RBF kernel is most popularly used with K-Nearest Neighbors and Support Vector Machines.
Code of RBF in python:
def RBF(X, gamma):
# Free parameter gamma
if gamma == None:
gamma = 1.0/X.shape[1]
# RBF kernel Equation
K = np.exp(-gamma * np.sum((X - X[:,np.newaxis])**2, axis = -1))
return K
This function accepts two parameters, one is the dataset for sure, and another is the gamma parameter.
The gamma parameter can be any value that tunes the equation. You can try giving different values to
gamma to see the change in the accuracy of prediction.