[英]How can I export a gbm model in R?
Is there a standard (or available) way to export a gbm model in R? 是否有标准(或可用)方法在R中导出gbm模型? PMML would work, but when II try to use the pmml library, perhaps incorrectly, I get an error: PMML可以工作,但当II尝试使用pmml库时,可能不正确,我收到一个错误:
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
And the error I get is: 而我得到的错误是:
Error in UseMethod("pmml") : no applicable method for 'pmml' applied to an object of class "gbm"
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. 在任何情况下,我都可以使用另一种我可以编程解析的格式(我将在JVM上进行评分),但如果有办法让PMM工作,PMML会很棒。
You can do the job using the r2pmml
package . 你可以使用r2pmml
包来完成这项工作。 Currently, it supports regression (ie. distribution = "gaussian"
) and binary classification (ie. distribution = "adaboost"
or distribution = "bernoulli"
) model types. 目前,它支持回归(即distribution = "gaussian"
)和二元分类(即distribution = "adaboost"
或distribution = "bernoulli"
)模型类型。
Below is a sample code for the Auto MPG
dataset : 以下是Auto MPG
数据集的示例代码:
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.