predict.cv.glmnet.Rd
This function makes predictions from a cross-validated glmnet model, using
the stored "glmnet.fit"
object, and the optimal value chosen for
lambda
(and gamma
for a 'relaxed' fit.
# S3 method for cv.glmnet predict(object, newx, s = c("lambda.1se", "lambda.min"), ...) # S3 method for cv.relaxed predict(object, newx, s = c("lambda.1se", "lambda.min"), gamma = c("gamma.1se", "gamma.min"), ...)
object | Fitted |
---|---|
newx | Matrix of new values for |
s | Value(s) of the penalty parameter |
... | Not used. Other arguments to predict. |
gamma | Value (single) of 'gamma' at which predictions are to be made |
The object returned depends on the ... argument which is passed
on to the predict
method for glmnet
objects.
This function makes it easier to use the results of cross-validation to make a prediction.
Friedman, J., Hastie, T. and Tibshirani, R. (2008)
Regularization Paths for Generalized Linear Models via Coordinate
Descent, Journal of Statistical Software, Vol. 33, Issue 1, Feb 2010
https://www.jstatsoft.org/v33/i01/
https://arxiv.org/abs/1707.08692
Hastie, T., Tibshirani, Robert,
Tibshirani, Ryan (2019) Extended Comparisons of Best Subset Selection,
Forward Stepwise Selection, and the Lasso
glmnet
, and print
, and coef
methods, and
cv.glmnet
.
x = matrix(rnorm(100 * 20), 100, 20) y = rnorm(100) cv.fit = cv.glmnet(x, y) predict(cv.fit, newx = x[1:5, ])#> 1 #> [1,] 0.09337702 #> [2,] 0.09337702 #> [3,] 0.09337702 #> [4,] 0.09337702 #> [5,] 0.09337702coef(cv.fit)#> 21 x 1 sparse Matrix of class "dgCMatrix" #> 1 #> (Intercept) 0.09337702 #> V1 . #> V2 . #> V3 . #> V4 . #> V5 . #> V6 . #> V7 . #> V8 . #> V9 . #> V10 . #> V11 . #> V12 . #> V13 . #> V14 . #> V15 . #> V16 . #> V17 . #> V18 . #> V19 . #> V20 .#> 21 x 1 sparse Matrix of class "dgCMatrix" #> 1 #> (Intercept) 0.09337702 #> V1 . #> V2 . #> V3 . #> V4 . #> V5 . #> V6 . #> V7 . #> V8 . #> V9 . #> V10 . #> V11 . #> V12 . #> V13 . #> V14 . #> V15 . #> V16 . #> V17 . #> V18 . #> V19 . #> V20 .#> 1 2 #> [1,] 0.135033994 0.1255374559 #> [2,] 0.563796290 0.5593714796 #> [3,] 0.189078763 0.1902399348 #> [4,] -0.345108903 -0.3324224776 #> [5,] 0.001156588 -0.0004136382#> 1 #> [1,] 0.09337702 #> [2,] 0.09337702 #> [3,] 0.09337702 #> [4,] 0.09337702 #> [5,] 0.09337702coef(cv.fit)#> 21 x 1 sparse Matrix of class "dgCMatrix" #> 1 #> (Intercept) 0.09337702 #> V1 . #> V2 . #> V3 . #> V4 . #> V5 . #> V6 . #> V7 . #> V8 . #> V9 . #> V10 . #> V11 . #> V12 . #> V13 . #> V14 . #> V15 . #> V16 . #> V17 . #> V18 . #> V19 . #> V20 .#> 21 x 1 sparse Matrix of class "dgCMatrix" #> 1 #> (Intercept) 0.09337702 #> V1 . #> V2 . #> V3 . #> V4 . #> V5 . #> V6 . #> V7 . #> V8 . #> V9 . #> V10 . #> V11 . #> V12 . #> V13 . #> V14 . #> V15 . #> V16 . #> V17 . #> V18 . #> V19 . #> V20 .#> 1 2 #> [1,] 0.135033994 0.1255374559 #> [2,] 0.563796290 0.5593714796 #> [3,] 0.189078763 0.1902399348 #> [4,] -0.345108903 -0.3324224776 #> [5,] 0.001156588 -0.0004136382