How can I extract RandomForest from R for use in production?

I have a successful randomforest model and I want to integrate it into other software, I know that I can use some libraries (for example, fastRF in Java o ALGLIB DecisionForest for other languages), but how can I use a trained model in R? Do I need to relearn it in a new language?

Another idea is to somehow extract it, but I don’t know how to do it ...

Any help would be appreciated

Thanks in advance

+8
java r random-forest alglib
source share
2 answers

Take a look at the pmml package that generates PMML for various models, including RandomForest. Basic example:

#?randomForest library(randomForest) library(pmml) set.seed(131) ozone.rf <- randomForest(Ozone ~ ., data=airquality, mtry=3,importance=TRUE, na.action=na.omit) print(ozone.rf) ozone.rf.pmml <- pmml(ozone.rf) 
+13
source share

The randomForest object has all the information about each tree in the object. Each tree is not particularly difficult, although this can be misleading.

 iris.rf <- randomForest(Species ~ ., data=iris, importance=TRUE, proximity=TRUE) > names(iris.rf$forest) [1] "ndbigtree" "nodestatus" "bestvar" "treemap" "nodepred" [6] "xbestsplit" "pid" "cutoff" "ncat" "maxcat" [11] "nrnodes" "ntree" "nclass" "xlevels" 

To figure out how to use the forest outside R, you will need to look at the source code. Download the source package randomForest, extract tar.gz and look in the src directory. In rf.c you will see the classForest function (and for regression, look at regforest in regrf.c). Look at the function R. predandom.randomForest to see what it is called. You may need to use getAnywhere ("predict.randomForest") to see it within R.

It will take quite a while to extract information from R and predict in another package, so you will need to think carefully before you do it. Converting the software that you intend to use may be simpler.

+2
source share

All Articles