Skip to contents

alpha = (K + lambda I)^-1 y with K_ij = k((x_i - x_j) / h) for the smoothing kernels (gaussian is the normal density) and f(x0) = sum_i alpha_i k((x0 - x_i) / h) (ESL eq 5.55).

Usage

kernel_ridge_regression(
  X,
  y,
  kernel = "gaussian",
  lam = 1,
  x_eval = NULL,
  bandwidth = NULL
)

Arguments

X

Predictor.

y

Response.

kernel

"gaussian", "epanechnikov" or "uniform".

lam

Ridge penalty, > 0.

x_eval

Evaluation points (default X).

bandwidth

Bandwidth; Silverman's rule when NULL.

Value

Named list: x_eval, y_hat, alpha, bandwidth, penalty, n_obs.

References

Hastie, Tibshirani & Friedman (2009), sec. 5.8.

Examples

x <- (1:25) / 25
kernel_ridge_regression(x, sin(6 * x), lam = 0.1, bandwidth = 0.2, x_eval = c(0.3, 0.6))$y_hat
#> [1]  0.9313952 -0.4340773