| grid.search | R Documentation |
Performs an optimized grid search to find the regularization parameter \lambda that minimizes the
cross-validation metric for ridge regression.
grid.search(formula, data, subset, na.action, K = 10L,
generalized = FALSE, seed = 1L, n.threads = 1L,
tol = 1e-7, max.lambda = 10000, precision = 0.1,
center = TRUE)
formula |
a |
data |
a data frame, list or environment containing the variables in the model. See
|
subset |
a specification of the rows/observations to be used. See |
na.action |
a function indicating how |
K |
an integer specifying the number of folds. For Leave-One-Out CV, set |
generalized |
if |
seed |
an integer used to initialize the random number generator for reproducible K-fold splits. |
n.threads |
an integer specifying the number of threads. For K-fold CV, parallelization occurs across
folds; for GCV/LOOCV, it occurs across the |
tol |
numeric scalar specifying the tolerance for rank estimation in the SVD. See |
max.lambda |
numeric scalar for the maximum |
precision |
numeric scalar specifying the step size (increment) between |
center |
if |
grid.search is designed for high-performance parameter tuning. Unlike naive implementations that
refit the model for every grid point, this function utilizes Singular Value Decomposition (SVD) of the
design matrix to evaluate the entire grid analytically.
For Generalized Cross-Validation (GCV) and Leave-One-Out (LOOCV), the SVD is computed once. Each
\lambda in the grid is then evaluated by updating the diagonal "shrinkage" matrix, reducing the cost
of each grid point evaluation from O(np^2) to O(\min(n,p)).
The search begins at \lambda = 0 and increments by precision until max.lambda is reached
(inclusive). The function returns the \lambda that achieves the minimum cross-validation metric across
the scheme.
A list with the following components:
the minimum cross-validation metric.
the value of \lambda associated with the minimum metric.
cvLM
## Not run:
data(mtcars)
grid.search(
formula = mpg ~ .,
data = mtcars,
K = 5L, # Use 5-fold CV
max.lambda = 100, # Search values between 0 and 100
precision = 0.01 # Increment in steps of 0.01
)
grid.search(
formula = mpg ~ .,
data = mtcars,
K = nrow(mtcars), # Use LOOCV
max.lambda = 10000, # Search values between 0 and 10000
precision = 0.5 # Increment in steps of 0.5
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.