How to export gbm model to R?
Is there a standard (or available) way to export a gbm model to R? PMML will work, but when I try to use the pmml library, probably wrong, I get the error:
For example, my code looks something like this:
library("gbm")
library("pmml")
model <- gbm(
formula,
data = my.data,
distribution = "adaboost",
n.trees = 450,
n.minobsinnode = 10,
interaction.depth = 4, shrinkage=0.05, verbose=TRUE)
export <- pmml(model)
# and then export to xml
And I am getting the error:
Error in UseMethod("pmml") : no applicable method for 'pmml' applied to an object of class "gbm"
I have also tried traversal on dataset. Anyway, I could live with a different format that I can parse programmatically (I will be evaluating the JVM), but PMML would be great if there was a way to make this work.
source to share
You can get the job done using r2pmml
package . It currently supports regression (i.e. distribution = "gaussian"
) and binary classification (i.e. distribution = "adaboost"
or distribution = "bernoulli"
) model types .
Below is the sample Auto MPG
dataset code :
library("gbm")
library("r2pmml")
auto = read.csv(file = "AutoNA.csv", header = TRUE)
auto.formula = gbm(mpg ~ ., data = auto, interaction.depth = 3, shrinkage = 0.1, n.trees = 100, response.name = "mpg")
print(auto.formula)
r2pmml(auto.formula, "/tmp/gbm.pmml")
source to share