Combine multiple random forests contained in a list
I would say that the use of Reduce in this context is bad practice. from ?Reduce : "Reduce uses a binary function to successively combine the elements of a given vector and a possibly given initial value." combine() is obviously not a binary function. do.call() seems to be THE appropriate idiom. -- Bert
On Fri, Jul 26, 2013 at 9:26 PM, arun <smartpink111 at yahoo.com> wrote:
HI,
Using the example in ?combine
library(randomForest)
rf1 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
rf2 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
rf3 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
rf.all <- combine(rf1, rf2, rf3)
lst1<- list(rf1,rf2,rf3)
rf.allL<- do.call(`combine`,lst1)
#or
rf.allL<- Reduce(`combine,lst1)
identical(rf.all,rf.allL)
#[1] TRUE
A.K.
Is there a quick and easy way to pass randomForest objects contained in a list into the combine() function?
As a result of calling randomForest through lapply(), I now have 10 randomForests in a list (rfors)
I want to combine all 10 of them. Understandably combine(rfors)
doesn't work as it doesn't recognise the individual forests within the
list. I have spend quite sometime messing around with unlist(), lapply()
and apply() to try and extract the information in a suitable format but
to no avail. The only thing that works is combine(rfors[[1]],
rfors[[2]] ...etc).
This is a bit cumbersome though, not least because the number of
random forests I'll need to combine is likely to change. Any sleek and
elegant solution to this someone can suggest?
Thanks in advance for any help.
Anna
______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm