问题描述
我在通过 Caret 加载 RWeka 包的已保存 M5 实现后出现错误.
I'm coming up with an error after loading a saved M5 implementation of the RWeka package via Caret.
.jcall(o, "Ljava/lang/Class;", "getClass") 中的错误:
RcallMethod:尝试调用一个 NULL 对象的方法.
RcallMethod: attempt to call a method of a NULL object.
重现错误:
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.
这篇文章 表示 RWeka 对象是对 Java 对象的引用,该对象必须被序列化才能正确保存/加载.
This post indicates that RWeka objects are references to a Java object, and that object must be serialized in order to save/load properly.
但是,我找不到将其扩展到 Caret 包实现的正确命令.
However, I cannot find the right commands to extend this to the Caret package implementation.
推荐答案
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")
这可能对您有所帮助.
顺便说一句有没有可以将 J48 Rweka 分类器变成规则的方法?
btwAre there methods that can make a J48 Rweka classifier into rules?
这篇关于保存/加载 M5 RWeka 插入符号模型失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!