如何在R中导出gbm模型? [英] How can I export a gbm model in R?
问题描述
是否存在用于在R中导出gbm模型的标准(或可用)方法? PMML可以工作,但是当我尝试使用pmml库时,也许是错误地,我得到了一个错误:
Is there a standard (or available) way to export a gbm model in R? PMML would work, but when I I try to use the pmml library, perhaps incorrectly, I get an error:
例如,我的代码与此类似:
For example, my code looks similar to 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
我得到的错误是:
Error in UseMethod("pmml") : no applicable method for 'pmml' applied to an object of class "gbm"
我也尝试过传递数据集.无论如何,我都可以使用其他可以通过编程方式解析的格式(我将在JVM上得分),但是如果有一种方法可以使PMML很好,那么PMML将会很棒.
I've also tried passing in the dataset. In any case, I could live with another format I can parse programmatically (I'll be scoring on the JVM) but PMML would be great if there is a way to make that work.
推荐答案
您可以使用 r2pmml
包.当前,它支持回归模型(即distribution = "gaussian"
)和二进制分类模型(即distribution = "adaboost"
或distribution = "bernoulli"
).
You can do the job using the r2pmml
package. Currently, it supports regression (ie. distribution = "gaussian"
) and binary classification (ie. distribution = "adaboost"
or distribution = "bernoulli"
) model types.
以下是 Auto MPG
数据集的示例代码:
Below is a sample code for the Auto MPG
dataset:
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")
这篇关于如何在R中导出gbm模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!