Learn R Programming

FastKRR (version 0.1.2)

plot.krr: Plot method for fitted Kernel Ridge Regression (KRR) models

Description

Visualizes fitted results from a Kernel Ridge Regression (KRR) model. Automatically generates predictions on a regular grid (120% of training sample size) and overlays them with training data.

Usage

# S3 method for krr
plot(x, show_points = TRUE, ...)

Value

A ggplot object showing the fitted regression curve.

Arguments

x

A fitted KRR model (class "krr") returned by fastkrr.

show_points

Logical; if TRUE, displays the training data points. Default = TRUE.

...

Additional arguments (currently ignored).

Details

For multivariate inputs (\(d \ge 2\)), visualization requires fixing all but one variable. For example, in 2D, one can plot \(f(x_1, x_2 = \bar{x}_2)\) to examine the effect of \(x_1\) while holding \(x_2\) at its mean.

See Also

fastkrr, predict.krr

Examples

Run this code
# \donttest{
set.seed(1)
n = 1000
rho = 1
X = runif(n, 0, 1)
y = sin(2*pi*X^3) + rnorm(n, 0, 0.1)

model_exact = fastkrr(X, y, kernel = "gaussian", rho = rho, opt = "exact", verbose = FALSE)
plot(model_exact)
# }

Run the code above in your browser using DataLab