elnet_cv {pense} | R Documentation |
Perform k-fold cross-validation for elnet
.
elnet_cv(x, y, alpha, nlambda = 100, lambda, weights, intercept = TRUE, cv_k = 10, cv_measure, ncores = getOption("mc.cores", 1L), cl = NULL, options = en_options_aug_lars(), lambda_min_ratio, ...)
x |
data matrix with predictors |
y |
response vector |
alpha |
controls the balance between the L1 and the L2 penalty.
|
nlambda |
size of the lambda grid if |
lambda |
a grid of decreasing lambda values. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
intercept |
should an intercept be estimated? |
cv_k |
number of cross validation folds. |
cv_measure |
function (name) which takes a matrix of residuals and returns a performance measure for each column. |
ncores, cl |
the number of processor cores or an actual |
options |
additional options for the EN algorithm. See
|
lambda_min_ratio |
if the lambda grid should be automatically defined,
the ratio of the smallest to the largest lambda value in the grid. The
default is |
... |
additional arguments passed on to |
lambda |
vector of lambda values. |
status |
integer specifying the exit status of the EN algorithm. |
message |
explanation of the exit status. |
coefficients |
matrix of regression coefficients. Each column corresponds to the estimate for the lambda value at the same index. |
residuals |
matrix of residuals. Each column corresponds to the residuals for the lambda value at the same index. |
cvres |
data frame with lambda, average cross-validated performance and the estimated standard deviation. |
elnet
to compute only the solution path, without
selecting the optimal penalty parameter using CV.
# Generate some dummy data set.seed(12345) n <- 30 p <- 15 x <- 1 + matrix(rnorm(n * p), ncol = p) y <- x %*% c(2:5, numeric(p - 4)) + rnorm(n) x_test <- matrix(rnorm(10 * n * p), ncol = p) y_test <- drop(x_test %*% c(2:5, numeric(p - 4)) + rnorm(n)) # Compute the classical EN and select lambda based on CV set.seed(1234) est <- elnet_cv( x, y, alpha = 0.6, nlambda = 100 ) # The optimal lambda according to CV is est$lambda_opt plot(est) # and the RMSPE at this lambda is sqrt(mean((y_test - predict(est, x_test))^2))