-1

I have build an application connecting R and java using the RServe package. In this project I use neuralnet to predict output. Where is the source code that I use are as follows:

myneuralnetscript=function(){   
    trainingData = read.csv("D:\\Kuliah\\Semester V\\TA\\Implementasi\\training.csv")
    testingData = read.csv("D:\\Kuliah\\Semester V\\TA\\Implementasi\\testing.csv")

    X1training <- trainingData$open
    X2training <- trainingData$high
    X3training <- trainingData$low
    X4training <- trainingData$close
    X5training <- trainingData$volume
    targetTraining <- trainingData$target

    X1testing <- testingData$open
    X2testing <- testingData$high
    X3testing <- testingData$low
    X4testing <- testingData$close
    X5testing <- testingData$volume
    targetTesting <- testingData$target

    xTraining <- cbind(X1training,X2training,X3training,X4training,X5training)

    sum.trainingData <- data.frame(xTraining,targetTraining)

    net.sum <- neuralnet(targetTraining~X1training+X2training+X3training+X4training+X5training, sum.trainingData, hidden=5,act.fct="logistic")

    xTesting <- cbind(X1testing,X2testing,X3testing,X4testing,X5testing)

    sum.testingData <- data.frame(xTesting,targetTesting)

    result <- compute(net.sum,sum.testingData[,1:5])

    return(result)
}

The output generated as follows:

enter image description here

Here the program from Java to access the results of the R.

public static void main(String[] args) {

    RConnection connection = null;

    try {
        /* Create a connection to Rserve instance running on default port
         * 6311
         */
        connection = new RConnection();

  //Directory of R script
        connection.eval("source('D:\\\\Kuliah\\\\Semester V\\\\TA\\\\Implementasi\\\\R\\\\neuralNet.R')");

 //Call method
        double output = connection.eval("myneuralnetscript()").asDouble();

        System.out.println(output);   
} catch (RserveException | REXPMismatchException e) {
        System.out.println("There is some problem indeed...");
    }
}

However, the output that appears is "There is some problem indeed ...".

1 Answers1

0

Please do not catch exceptions just to print a useless message. Remove your try catch and declare main to throw Exception. That way you'll see the actual error.

Either Rserve is not running locally on 6311 or it's failing to evaluate or the result of second evaluation cannot be coerced into a single double.

When you run eval do

tryCatch({CODE},e=function ()e)

instead and check if return inherits from try-error and get the message

Lev Kuznetsov
  • 3,520
  • 5
  • 20
  • 33