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:
- Installing jdk-21 and jre-1.8 and adding them to environment variables path
- Install rJava after installing the above Java programs
- Installing
r2pmmlfrom source to get the latest version; updated R to the latest version - 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)
Your Java setup is definitely messy. Here's how to clean it up:
rJavapackage.JAVA_HOMEenvironment variable (GNU/Linux style; see Windows documentation for Windows style):export JAVA_HOME=/opt/jdk-11/.bindirectory of the newly exportedJAVA_HOMEenv-var to thePATHenvironment variable (again, the following uses GNU/Linux style):export PATH=$PATH:$JAVA_HOME/bin/.java --versioninto it, it should print out the exact version string of your JDK 11.r2pmmlpackage works fine now, no need for additional R level changes!You may also invoke the
r2pmml::r2pmml()utility function with theverbose = TRUEflag 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.