[R] Saving a Random Forest Model
Lorenzo Isella
lorenzo.isella at gmail.com
Sat Mar 23 11:35:48 CET 2013
Dear All,
Please consider the snippet at the end of the email
The output of the randomForest model is rf1 (i.e. the trained model).
Now, is there a way to save this rf1 so that, in a different R session, I
can just load it without repeating the analysis?
Of course I have in mind much more CPU-intensive simulations than in this
artificial example (where it would be really unpractical to recalculate
everything and the model has to be applied to different data sets at
different time or needs to be combined with other models).
Any suggestion is welcome.
Cheers
Lorenzo
######################################
# simulate the data
x1=rnorm(1000)
x2=rnorm(1000,x1,1)
y=2*x1+rnorm(1000,0,.5)
df=data.frame(y,x1,x2,x3=rnorm(1000),x4=rnorm(1000),x5=rnorm(1000))
# run the randomForest implementation
library(randomForest)
rf1 <- randomForest(y~., data=df, mtry=2, ntree=50, importance=TRUE)
####################################
More information about the R-help
mailing list