Implement a polynomial kernel function used in SVMs. Given two input vectors x1 and x2, a degree d, and an optional constant c (default 1), compute K(x1, x2) = (x1 . x2 + c)^d.
import numpy as np
def polynomial_kernel(x1: np.ndarray, x2: np.ndarray, d: int, c: float = 1.0) -> float:
dot_product = np.dot(x1, x2)
return (dot_product + c) ** dc to the dot product.d.The polynomial kernel maps inputs into a higher-dimensional feature space without explicitly computing the transformation, enabling SVMs to find non-linear decision boundaries.