predict.cv.glmnet: make predictions from a "cv.glmnet" object.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/predict.cv.glmnet.R

Description

This function makes predictions from a cross-validated glmnet model, using the stored "glmnet.fit" object, and the optimal value chosen for lambda.

Usage

1
2
3
4
## S3 method for class 'cv.glmnet'
predict(object, newx, s=c("lambda.1se","lambda.min"),...)
## S3 method for class 'cv.glmnet'
coef(object,s=c("lambda.1se","lambda.min"),...)

Arguments

object

Fitted "cv.glmnet" object.

newx

Matrix of new values for x at which predictions are to be made. Must be a matrix; can be sparse as in Matrix package. See documentation for predict.glmnet.

s

Value(s) of the penalty parameter lambda at which predictions are required. Default is the value s="lambda.1se" stored on the CV object. Alternatively s="lambda.min" can be used. If s is numeric, it is taken as the value(s) of lambda to be used.

...

Not used. Other arguments to predict.

Details

This function makes it easier to use the results of cross-validation to make a prediction.

Value

The object returned depends the ... argument which is passed on to the predict method for glmnet objects.

Author(s)

Jerome Friedman, Trevor Hastie and Rob Tibshirani
Maintainer: Trevor Hastie <hastie@stanford.edu>

References

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
http://www-stat.stanford.edu/~hastie/Papers/glmnet.pdf
http://www.jstatsoft.org/v33/i01/

See Also

glmnet, and print, and coef methods, and cv.glmnet.

Examples

1
2
3
4
5
6
7
x=matrix(rnorm(100*20),100,20)
y=rnorm(100)
cv.fit=cv.glmnet(x,y)
predict(cv.fit,newx=x[1:5,])
coef(cv.fit)
coef(cv.fit,s="lambda.min")
predict(cv.fit,newx=x[1:5,],s=c(0.001,0.002))

Example output

Loading required package: Matrix
Loading required package: foreach
Loaded glmnet 2.0-10

             1
[1,] 0.2145698
[2,] 0.2145698
[3,] 0.2145698
[4,] 0.2145698
[5,] 0.2145698
21 x 1 sparse Matrix of class "dgCMatrix"
                    1
(Intercept) 0.2145698
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.2145698
V1          .        
V2          .        
V3          .        
V4          .        
V5          .        
V6          .        
V7          .        
V8          .        
V9          .        
V10         .        
V11         .        
V12         .        
V13         .        
V14         .        
V15         .        
V16         .        
V17         .        
V18         .        
V19         .        
V20         .        
               1           2
[1,]  0.04556346  0.04879641
[2,]  1.17832162  1.16989287
[3,] -0.51170087 -0.50299142
[4,]  0.91194758  0.90572244
[5,] -0.33635267 -0.32672762

glmnet documentation built on May 29, 2017, 2:07 p.m.