A Nadaraya-Watson kernel regression model. Notes ----- The Nadaraya-Watson regression model is .. math:: f(x) = \sum_i w_i(x) y_i where the sample weighting functions, :math:`w_i`, are simply .. math:: w_i(x) = \\
(self, kernel=None)
| 3 | |
| 4 | class KernelRegression: |
| 5 | def __init__(self, kernel=None): |
| 6 | """ |
| 7 | A Nadaraya-Watson kernel regression model. |
| 8 | |
| 9 | Notes |
| 10 | ----- |
| 11 | The Nadaraya-Watson regression model is |
| 12 | |
| 13 | .. math:: |
| 14 | |
| 15 | f(x) = \sum_i w_i(x) y_i |
| 16 | |
| 17 | where the sample weighting functions, :math:`w_i`, are simply |
| 18 | |
| 19 | .. math:: |
| 20 | |
| 21 | w_i(x) = \\frac{k(x, x_i)}{\sum_j k(x, x_j)} |
| 22 | |
| 23 | with `k` being the kernel function. |
| 24 | |
| 25 | Observe that `k`-nearest neighbors |
| 26 | (:class:`~numpy_ml.nonparametric.KNN`) regression is a special case of |
| 27 | kernel regression where the `k` closest observations have a weight |
| 28 | `1/k`, and all others have weight 0. |
| 29 | |
| 30 | Parameters |
| 31 | ---------- |
| 32 | kernel : str, :doc:`Kernel <numpy_ml.utils.kernels>` object, or dict |
| 33 | The kernel to use. If None, default to |
| 34 | :class:`~numpy_ml.utils.kernels.LinearKernel`. Default is None. |
| 35 | """ |
| 36 | self.parameters = {"X": None, "y": None} |
| 37 | self.hyperparameters = {"kernel": str(kernel)} |
| 38 | self.kernel = KernelInitializer(kernel)() |
| 39 | |
| 40 | def fit(self, X, y): |
| 41 | """ |
nothing calls this directly
no test coverage detected