0

尝试在样本数据集上执行 RandomForest,但未发现面临以下问题的方法。

使用以下库。

使用这些外部库。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

使用此代码执行 RandomForest 分类算法。

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$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(randomForest)");
        engine.eval("set.seed(123)");
        engine.eval("classifier = randomForest(x = training_set[-3], y = training_set$Purchased, ntree = 10)");
        engine.eval("y_pred = predict(classifier, newdata = test_set[-3])");

得到下面的异常

Exception in thread "main" org.renjin.eval.EvalException: org.renjin.gnur.api.Utils.R_qsort_I(Lorg/renjin/gcc/runtime/DoublePtr;Lorg/renjin/gcc/runtime/IntPtr;II)V
    at org.renjin.sexp.Closure.applyPromised(Closure.java:212)
    at org.renjin.primitives.special.UseMethod.apply(UseMethod.java:166)
    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:33)
Caused by: java.lang.NoSuchMethodError: org.renjin.gnur.api.Utils.R_qsort_I(Lorg/renjin/gcc/runtime/DoublePtr;Lorg/renjin/gcc/runtime/IntPtr;II)V
    at org.renjin.cran.randomForest.rfutils__.makeA(rfutils.c:76)
    at org.renjin.cran.randomForest.rf__.classRF(rf.c:218)
    at org.renjin.cran.randomForest.randomForest.classRF(Unknown Source)
    at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
    at org.renjin.primitives.Native.dotC(Native.java:190)
    at org.renjin.primitives.R$primitive$$C.applyPromised(R$primitive$$C.java:69)
    at org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100)
    at org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at org.renjin.sexp.Promise.doEval(Promise.java:87)
    at org.renjin.sexp.Promise.force(Promise.java:81)
    at org.renjin.primitives.R$primitive$$bracket.applyPromised(R$primitive$$bracket.java:34)
    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.primitives.special.IfFunction.apply(IfFunction.java:40)
    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)
    ... 13 more
4

1 回答 1

0

看起来新的 3.5 beta 版本和为 Renjin 0.9 构建的包之间存在一些二进制不兼容。目前,使用仁进 0.9.2726 应该可以避免该问题。

Renjin 3.5 应在 9 月底之前发布,并将包括所有 CRAN+BioConductor 软件包的新版本。

于 2019-09-02T07:43:07.497 回答