Save/load a M5 RWeka caret model fails

﹥>﹥吖頭↗ 提交于 2019-12-07 18:31:00

问题


I'm coming up with an error after loading a saved M5 implementation of the RWeka package via Caret.

Error in .jcall(o, "Ljava/lang/Class;", "getClass") :

RcallMethod: attempt to call a method of a NULL object.

To reproduce the error:

library(caret); library(RWeka)
data(GermanCredit)

myModel <- train(Duration~Amount, data=GermanCredit, method="M5")
predict(myModel, GermanCredit[1,]) # Works.

save(myModel, file="myModel.rda")
load("myModel.rda")
predict(myModel, GermanCredit[1,]) # Produces the RcallMethod error.

This post indicates that RWeka objects are references to a Java object, and that object must be serialized in order to save/load properly.

However, I cannot find the right commands to extend this to the Caret package implementation.


回答1:


http://one-line-it.blogspot.tw/2013/03/r-store-rweka-model-to-file.html

library(RWeka)
j48.model <- J48(formula=class ~ ., data=data)
library(rJava)
.jcache(j48.model$classifier)
save(j48.model, file="j48.model.rda")

This may help you.

btw Are there methods that can make a J48 Rweka classifier into rules?



来源:https://stackoverflow.com/questions/27991197/save-load-a-m5-rweka-caret-model-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!