"Häring, Tim (LWF)"
2009-Jan-15 16:31 UTC
[R] problems with extractPrediction in package caret
Hi list, I´m working on a predictive modeling task using the caret package. I found the best model parameters using the train() and trainControl() command. Now I want to evaluate my model and make predictions on a test dataset. I tried to follow the instructions in the manual and the vignettes but unfortunately I´m getting an error message I can`t figure out. Here is my code: rfControl <- trainControl(method = "oob", returnResamp = "all", returnData=TRUE, verboseIter = TRUE) rftrain <- train(x=train_x, y=trainclass, method="rf", tuneGrid=tuneGrid, tr.control=rfControl) pred <- predict(rftrain) pred # this works fine expred <- extractPrediction(rftrain) Error in models[[1]]$trainingData : $ operator is invalid for atomic vectors My predictors are 28 numeric attributes and one factor. I`m working with the latest version of caret and R 2.7.2 on WinXP. Any advice is very welcome. Thanks. TIM ------------------------------------------------------------------------------- Dipl.-Geogr. Tim Häring Sachgebiet Standort und Bodenschutz (SG 2.1) Bayerische Landesanstalt für Wald und Forstwirtschaft Am Hochanger 11 D-85354 Freising Tel.: +49-(0)8161/71-4769 E-Mail: tim.haering@lwf.bayern.de http://www.lwf.bayern.de [[alternative HTML version deleted]]
H?ring, Tim (LWF) wrote:> Hi list, > > I?m working on a predictive modeling task using the caret package. > I found the best model parameters using the train() and trainControl() command. Now I want to evaluate my model and make predictions on a test dataset. I tried to follow the instructions in the manual and the vignettes but unfortunately I?m getting an error message I can`t figure out. > Here is my code: > rfControl <- trainControl(method = "oob", returnResamp = "all", returnData=TRUE, verboseIter = TRUE) > rftrain <- train(x=train_x, y=trainclass, method="rf", tuneGrid=tuneGrid, tr.control=rfControl) > > pred <- predict(rftrain) > pred # this works fine > expred <- extractPrediction(rftrain) > > Error in models[[1]]$trainingData : > $ operator is invalid for atomic vectorsI cannot reproduce it (not having your data) and I doubt you are using the most recent version which is 3.51. Anyway, *if* it is a bug, then please report to the package maintainer. Best, Uwe Ligges> My predictors are 28 numeric attributes and one factor. > I`m working with the latest version of caret and R 2.7.2 on WinXP. > > Any advice is very welcome. > > Thanks. > TIM > > > ------------------------------------------------------------------------------- > Dipl.-Geogr. Tim H?ring > Sachgebiet Standort und Bodenschutz (SG 2.1) > Bayerische Landesanstalt f?r Wald und Forstwirtschaft > Am Hochanger 11 > D-85354 Freising > > Tel.: +49-(0)8161/71-4769 > E-Mail: tim.haering at lwf.bayern.de > http://www.lwf.bayern.de > > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at 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.
The issue is the usage of extractPrediction. expred <- extractPrediction(rftrain) should really be expred <- extractPrediction(list(rftrain)) Since this function is intended to get predictions across multiple models, the man file has a description of the first argument to teh funtion being "a list of objects of the class train." -- Max