I have a randomForest object that I want to save for later use. I've tried some of the following but with no luck.
save(topDawg , file="myRFobject.RData")
This just saves a string "topDawg"
> formula(topDawg)
Error in formula.default(topDawg) : invalid formula
> save(getTree(topDawg))
Error in save(getTree(topDawg)) : object ‘getTree(topDawg)’ not found
Any suggestions?
In R, after running "random forest" model, I can use save. image("***. RData") to store the model. Afterwards, I can just load the model to do predictions directly.
Summary. It is important to tune the number of trees in the Random Forest. To tune number of trees in the Random Forest, train the model with large number of trees (for example 1000 trees) and select from it optimal subset of trees. There is no need to train new Random Forest with different tree numbers each time.
I'm not sure exactly what you're trying to do here, since normally you save
an object and then load
it later, like this:
set.seed(71)
> irisrf <- randomForest(Species ~ ., data=iris, importance=TRUE,
+ proximity=TRUE)
> save(irisrf,file = "irisrf.RData")
>
> rm(irisrf)
> print(irisrf)
Error in print(irisrf) : object 'irisrf' not found
>
> load("irisrf.RData")
> print(irisrf)
Call:
randomForest(formula = Species ~ ., data = iris, importance = TRUE, proximity = TRUE)
Type of random forest: classification
Number of trees: 500
No. of variables tried at each split: 2
OOB estimate of error rate: 4.67%
Confusion matrix:
setosa versicolor virginica class.error
setosa 50 0 0 0.00
versicolor 0 47 3 0.06
virginica 0 4 46 0.08
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With