What is a polynomial kernel in SVM?
A polynomial kernel is a similarity function that lets an SVM model polynomial relationships between input features without explicitly creating every polynomial feature. It can learn curved decision boundaries when a straight line is insufficient.
Formula
K(x, z) = (gamma * (x · z) + coef0)^degreex · z: dot product of two feature vectors.degree: polynomial degree (for example,2or3), controlling the order of feature interactions.gamma: scales the dot product.coef0: constant offset; affects how lower-order and higher-order terms contribute.
In scikit-learn, use SVC(kernel='poly'). Its polynomial parameters are degree, gamma, and coef0; the regularization parameter C is tuned separately.
Beginner-friendly numerical example
Let x = (1, 2), z = (2, 3), gamma = 0.5, coef0 = 1, and degree = 2:
x · z = (1 * 2) + (2 * 3) = 8
K(x, z) = (0.5 * 8 + 1)^2
= 5^2
= 25Why is this different from a linear kernel? Expanding the square gives:
(gamma * (x · z) + coef0)^2
= gamma^2 * (x · z)^2
+ 2 * gamma * coef0 * (x · z)
+ coef0^2The squared dot-product term implicitly incorporates products between features, such as x1*x2. These interactions allow a linear separator in the implicit feature space to become nonlinear in the original space.
Important: the kernel output 25 is a similarity calculation, not a class probability.
Practical example: a center surrounded by alerts
Imagine a sensor with two readings. A central reading (0, 0) is Normal, while readings at (±2, 0) and (0, ±2) are Alert. A single straight line cannot place the center on one side and all surrounding points on the other. A degree-2 polynomial SVM can learn a boundary around the center.
PYTHONfrom sklearn.svm import SVC X = [[0, 0], [2, 0], [-2, 0], [0, 2], [0, -2]] y = [0, 1, 1, 1, 1] # 0=Normal, 1=Alert model = SVC(kernel='poly', degree=2, gamma=1, coef0=1, C=100) model.fit(X, y) print(model.predict([[0, 0], [2, 0], [0, 2]])) # [0 1 1]
When should you use a polynomial kernel?
- Use it when feature interactions or polynomial-shaped boundaries are plausible.
- Start with lower degrees, then tune
degree,gamma,coef0, andCusing cross-validation. Higher degree is not automatically better. - Scale numerical features using training-only preprocessing inside a pipeline; kernel values are sensitive to feature magnitudes.
- Compare against linear and RBF kernels on the same validation splits. Polynomial kernels can overfit or be computationally expensive on large datasets.
In short: a polynomial kernel computes (gamma * x·z + coef0)^degree, allowing SVMs to capture polynomial feature interactions without manually expanding them.
References
Learning Sequence
Machine Learning Curriculum
Explore Related Questions
Deepen your understanding across related Machine Learning topics.