Polynomial Kernel
Polynomial Kernel
The polynomial kernel is a popular kernel function used in SVM to model non-linear
decision boundaries. It allows SVM to effectively handle data that is not linearly
separable in the original feature space. The polynomial kernel is defined by the formula:
K (x, x') represents the polynomial kernel between two data points x and x'.
γ is a parameter that controls the influence of the dot product ⟨x, x'⟩.
r is an optional parameter that adds an additional constant term to the kernel.
d is the degree of the polynomial.
Code:
Code explanation:
1. Input:
The function takes two input matrices, X and Y, representing the data
points.
X has shape (m, n), where m is the number of data points and n is the
number of features.
Y has shape (p, n), where p is the number of data points (which can be
different from m) and n is the number of features.
2. Dot Product:
The code computes the dot product between the matrices X and Y using
the np.dot () function.
This step calculates the pairwise dot products between each pair of data
points in X and Y.
3. Polynomial Kernel Computation:
The polynomial kernel function is applied to the dot product matrix K.
The formula (gamma * K + coef0) **degree is used to compute the
polynomial kernel.
The parameter gamma controls the influence of the dot product term in
the polynomial kernel.
The parameter coef0 adds a constant term to the kernel.
The parameter degree specifies the degree of the polynomial.
4. Output:
The function returns the resulting polynomial kernel matrix K, which
represents the pairwise similarities or distances between the data points in
the higher-dimensional feature space.
The code efficiently computes the polynomial kernel matrix using the dot product and
the specified degree, gamma, and coef0 parameters. This kernel matrix can be used in
SVM for training and classification purposes, allowing SVM to learn non-linear decision
boundaries based on the polynomial kernel.
Characteristics of polynomial kernel in SVM algorithm:
It's important to note that the choice of the polynomial degree and other
hyperparameters depends on the specific dataset and problem at hand.
How the polynomial kernel works in higher dimensions:
1. Data Transformation:
The polynomial kernel first transforms the original data points from the
original feature space to a higher-dimensional feature space.
The transformation is achieved by computing the dot product of the data
points, which generates polynomial terms of various degrees.
2. Dot Product:
The polynomial kernel computes the dot product between the
transformed data points in the higher-dimensional feature space.
The dot product measures the similarity or distance between pairs of data
points.
By taking the dot product, the polynomial kernel captures interactions
between features in the original data points.
3. Polynomial Kernel Function:
After computing the dot product, the polynomial kernel applies a
polynomial function to the dot product result.
The polynomial function is defined by the formula: K (x, x') = (γ * ⟨x, x'⟩ +
r)^d.
The parameter γ controls the influence of the dot product term,
determining the weight assigned to the similarity or distance between
data points.
The parameter r is an optional constant term that adds a bias to the kernel
function.
The parameter d represents the degree of the polynomial, determining the
complexity of the decision boundary.
4. Decision Boundary in Higher Dimensions:
In the higher-dimensional feature space, the polynomial kernel constructs
a decision boundary that is linear in terms of the transformed data points.
Although the decision boundary may be linear in the higher-dimensional
space, it corresponds to a non-linear decision boundary in the original
feature space.
The polynomial kernel allows SVM to capture non-linear patterns and
relationships by exploiting the interactions between features through
polynomial terms.
Pictures: