找不到人人对象C_rpart

时间:2019-08-30 07:10:57

标签: renjin

尝试在我的Java项目中执行ML算法进行预测。 Found Renjin是在基于Java的项目中执行R代码最兼容的平台。尝试通过Renjin库执行R代码段,但出现以下错误。请提出建议。

Using these external libraries.
bitops-1.0-6-b237.jar
caTools-1.17.1-b220.jar
renjin-script-engine-3.5-beta65-jar-with-dependencies.jar
gcc-runtime-0.8.1938.jar
rpart-4.1-10-b20.jar

使用此代码执行决策树分类算法。

RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
        ScriptEngine engine = factory.getScriptEngine();
        engine.eval("dataset = read.csv('Social_Network_Ads.csv')");
        engine.eval("dataset = dataset[3:5]");
        engine.eval("dataset = read.csv('Social_Network_Ads.csv')");
        engine.eval("dataset = dataset[3:5]");
        engine.eval("dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1))");
        engine.eval("library(caTools)");
        engine.eval("set.seed(123)");
        engine.eval("split = sample.split(dataset$Purchased, SplitRatio = 0.75)");
        engine.eval("training_set = subset(dataset, split == TRUE)");
        engine.eval("test_set = subset(dataset, split == FALSE)");
        engine.eval("training_set[-3] = scale(training_set[-3])");
        engine.eval("test_set[-3] = scale(test_set[-3])");
        engine.eval("library(rpart)");
        engine.eval("classifier = rpart(formula = Purchased ~ ., data = training_set)");
        engine.eval("y_pred = predict(classifier, newdata = test_set[-3], type = 'class')");

Exception in thread "main" org.renjin.eval.EvalException: object 'C_rpart' not found
    at org.renjin.sexp.Symbol.eval(Symbol.java:329)
    at org.renjin.sexp.Promise.doEval(Promise.java:87)
    at org.renjin.sexp.Promise.force(Promise.java:81)
    at org.renjin.primitives.R$primitive$$Call.applyPromised(R$primitive$$Call.java:36)
    at org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100)
    at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at org.renjin.primitives.special.AssignLeftFunction.assignLeft(AssignLeftFunction.java:58)
    at org.renjin.primitives.special.AssignLeftFunction.apply(AssignLeftFunction.java:42)
    at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39)
    at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at org.renjin.sexp.Closure.applyPromised(Closure.java:200)
    at org.renjin.sexp.Closure.apply(Closure.java:133)
    at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at org.renjin.primitives.special.AssignLeftFunction.assignLeft(AssignLeftFunction.java:58)
    at org.renjin.primitives.special.AssignLeftFunction.apply(AssignLeftFunction.java:42)
    at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at org.renjin.sexp.ExpressionVector.eval(ExpressionVector.java:85)
    at org.renjin.eval.Context.evaluate(Context.java:280)
    at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:174)
    at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:133)
    at RTest.main(RTest.java:34)

0 个答案:

没有答案