anubhuti mishra
anubhuti mishra

Reputation: 130

Java executable error with r2pmml when converting XGBoost model

I am trying to export an xgboost model from R to PMML. This PMML model will be integrated into a Java-based electronic medical record (EMR) system. I have tried everything and keep getting the following error:

Error in .convert(tempfile, file, converter, converter_classpath, verbose): Java is not installed, or the Java executable is not on system path (error code 127)

I am working with Windows 10, 64-bit machine, and have tried the following:

  1. Installing jdk-21 and jre-1.8 and adding them to environment variables path
  2. Install rJava after installing the above Java programs
  3. Installing r2pmml from source to get the latest version; updated R to the latest version
  4. Updated JAVA_HOME in R to point to jre-1.8

I am not even able to replicate this example from the r2pmml documentation. I get the same Java error as above:

library("xgboost")
library("r2pmml")
data(iris)
iris_X = iris[, -ncol(iris)]
iris_y = iris[, ncol(iris)]
# Convert from factor to integer[0, num_class]
iris_y = (as.integer(iris_y) - 1)
iris.matrix = model.matrix(~ . - 1, data = iris_X)
iris.DMatrix = xgb.DMatrix(iris.matrix, label = iris_y)
iris.fmap = as.fmap(iris.matrix)
iris.xgboost = xgboost(data = iris.DMatrix,
objective = "multi:softprob", num_class = 3, nrounds = 11)
iris.xgboost = decorate(iris.xgboost, iris.fmap,
response_name = "Species", response_levels = c("setosa", "versicolor", "virginica"))
pmmlFile = file.path(tempdir(), "Iris-XGBoost.pmml")
r2pmml(iris.xgboost, pmmlFile, compact = FALSE)
compactPmmlFile = file.path(tempdir(), "Iris-XGBoost-compact.pmml")
r2pmml(iris.xgboost, compactPmmlFile, compact = TRUE)

Upvotes: 0

Views: 88

Answers (1)

user1808924
user1808924

Reputation: 4926

Your Java setup is definitely messy. Here's how to clean it up:

  1. Install a LTS-version of JDK - one of 8, 11 or 17. The Java "configuration" should be JDK (complete toolset) not JRE (incomplete toolset).
  2. There is no need for installing the rJava package.
  3. Export the location of the installed JDK as JAVA_HOME environment variable (GNU/Linux style; see Windows documentation for Windows style): export JAVA_HOME=/opt/jdk-11/.
  4. Append the bin directory of the newly exported JAVA_HOME env-var to the PATH environment variable (again, the following uses GNU/Linux style): export PATH=$PATH:$JAVA_HOME/bin/.
  5. Push/Re-apply env-var changes on the system level. When you open a new terminal window and type java --version into it, it should print out the exact version string of your JDK 11.
  6. Congrats, the r2pmml package works fine now, no need for additional R level changes!

You may also invoke the r2pmml::r2pmml() utility function with the verbose = TRUE flag on. This will print out the exact command-line sequence, which you can re-try one by one on a new terminal window and see where the original misconfiguration error resided.

Upvotes: 1

Related Questions