Question

I have a successful randomforest model, and I want to integrate it in another software, I know that I can use some libraries (like fastRF in Java o ALGLIB's DecisionForest for other languages) but how I can use the "model" trained in R? I have to re-train it in the new language?

Another view is extract it somehow, but I dont't know how to do it...

Any help will be appreciated

Thanks in advance

Was it helpful?

Solution

Take a look at the pmml package which generate PMML for various models, RandomForest included. A 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)

OTHER TIPS

The randomForest object has all the information about each tree in the object. Each tree is not particularly complicated, though it can be confusing.

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 work out how to use the forest outside of R, you'll have to look at the source code. Download the source package of randomForest, extract the tar.gz and look in the src directory. In rf.c you will see the function classForest (and for regression look at regForest in regrf.c). Look at the R function predict.randomForest to see how its called. You might have to use getAnywhere("predict.randomForest") to see it within R.

It will require a fair bit of mucking around to extract the R information and predict in another package, so you'd have to think carefully before you actually did this. Refitting in the software you intend to use may be more straightforward.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top