Hi: Here's what I got when I ran your code:
library('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.1213114 [2,] 0.1213114 [3,] 0.1213114 [4,] 0.1213114 [5,] 0.1213114 > coef(cv.fit) 21 x 1 sparse Matrix of class "dgCMatrix" 1 (Intercept) 0.1213114 V1 0.0000000 V2 0.0000000 V3 0.0000000 V4 0.0000000 V5 0.0000000 V6 0.0000000 V7 0.0000000 V8 0.0000000 V9 0.0000000 V10 0.0000000 V11 0.0000000 V12 0.0000000 V13 0.0000000 V14 0.0000000 V15 0.0000000 V16 0.0000000 V17 0.0000000 V18 0.0000000 V19 0.0000000 V20 0.0000000 ### Check against the versions of the packages listed below: > sessionInfo() R version 2.14.0 (2011-10-31) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] glmnet_1.7.1 Matrix_1.0-1 lattice_0.20-0 ggplot2_0.8.9 proto_0.3-9.2 [6] reshape_0.8.4 plyr_1.6 loaded via a namespace (and not attached): [1] tools_2.14.0 Dennis On Tue, Nov 1, 2011 at 3:34 PM, asafw <assafweinst...@gmail.com> wrote: > > Hi there, > > I am trying to use predict() with an object returned by cv.glmnet(), and get > the following error: > no applicable method for 'predict' applied to an object of class "cv.glmnet" > > What's wrong? > > my code: > > 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) > > Thanks so much, > > Asaf > > -- > View this message in context: > http://r.789695.n4.nabble.com/predict-for-a-cv-glmnet-returns-an-error-tp3965744p3965744.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.