Caret Model random forest into PMML error

旧巷老猫 提交于 2019-12-02 02:29:33

You cannot invoke the pmml method with train or train.formula types (ie. this is the type of your model.Test object).

Caret documentation for the train method says that you can access the best model as the finalModel field. You can invoke the pmml method on that object then.

rf = model.Test$finalModel
pmml(rf)

Unfortunately, it turns out that Caret specifies the RF model using the "matrix interface" (ie. by setting the x and y fields), not using the more common "formula interface" (ie. by setting the formula field). AFAIK, the "pmml" package does not support the export of such RF models.

So, looks like your best option is to use a two-level approach. First, use the Caret package to find the most appropriate RF parametrization for your dataset. Second, train the final RF model manually using the "formula interface" with this parametrization.

You can use the r2pmml package to do the job:

library("caret")
library("r2pmml")

data(iris)

train.rf = train(Species ~ ., data = iris, method = "rf")
print(train.rf)
r2pmml(train.rf, "/tmp/train-rf.pmml")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!