The degree-`d` polynomial kernel. Notes ----- For input vectors :math:`\mathbf{x}` and :math:`\mathbf{y}`, the polynomial kernel is: .. math:: k(\mathbf{x}, \mathbf{y}) = (\gamma \mathbf{x}^\\top \mathbf{y} + c_0)^d In contrast
(self, d=3, gamma=None, c0=1)
| 118 | |
| 119 | class PolynomialKernel(KernelBase): |
| 120 | def __init__(self, d=3, gamma=None, c0=1): |
| 121 | """ |
| 122 | The degree-`d` polynomial kernel. |
| 123 | |
| 124 | Notes |
| 125 | ----- |
| 126 | For input vectors :math:`\mathbf{x}` and :math:`\mathbf{y}`, the polynomial |
| 127 | kernel is: |
| 128 | |
| 129 | .. math:: |
| 130 | |
| 131 | k(\mathbf{x}, \mathbf{y}) = (\gamma \mathbf{x}^\\top \mathbf{y} + c_0)^d |
| 132 | |
| 133 | In contrast to the linear kernel, the polynomial kernel also computes |
| 134 | similarities *across* dimensions of the **x** and **y** vectors, |
| 135 | allowing it to account for interactions between features. As an |
| 136 | instance of the dot product family of kernels, the polynomial kernel is |
| 137 | invariant to a rotation of the coordinates about the origin, but *not* |
| 138 | to translations. |
| 139 | |
| 140 | Parameters |
| 141 | ---------- |
| 142 | d : int |
| 143 | Degree of the polynomial kernel. Default is 3. |
| 144 | gamma : float or None |
| 145 | A scaling parameter for the dot product between `x` and `y`, |
| 146 | determining the amount of smoothing/resonlution of the kernel. |
| 147 | Larger values result in greater smoothing. If None, defaults to 1 / |
| 148 | `C`. Sometimes referred to as the kernel bandwidth. Default is |
| 149 | None. |
| 150 | c0 : float |
| 151 | Parameter trading off the influence of higher-order versus lower-order |
| 152 | terms in the polynomial. If `c0` = 0, the kernel is said to be |
| 153 | homogenous. Default is 1. |
| 154 | """ |
| 155 | super().__init__() |
| 156 | self.hyperparameters = {"id": "PolynomialKernel"} |
| 157 | self.parameters = {"d": d, "c0": c0, "gamma": gamma} |
| 158 | |
| 159 | def _kernel(self, X, Y=None): |
| 160 | """ |