如何在R中导出gbm模型?

在R中导出gbm模型是否有标准(或可用的)方法?PMML是可以的,但当我尝试使用pmml库时,可能使用方法不正确,出现了错误:

例如,我的代码看起来类似于这样:

  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)  # 然后导出到xml

我得到的错误是:

Error in UseMethod("pmml") : no applicable method for 'pmml' applied to an object of class "gbm"

我也尝试过传入数据集。无论如何,如果有其他我可以编程解析的格式,我也可以接受(我将在JVM上进行评分),但如果有办法让PMML工作,那就太好了。


回答:

你可以使用r2pmml来完成这项工作。目前,它支持回归(即distribution = "gaussian")和二元分类(即distribution = "adaboost"distribution = "bernoulli")模型类型。

下面是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")

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注