R model export with r2pmml

897 views
Skip to first unread message

Benjamin Auffarth

unread,
Oct 8, 2015, 7:58:59 AM10/8/15
to Java PMML API
Hi,
I was trying the R exports today. While github example of the random forest with iris works, other models do not.

Using a decision tree or a linear model throws an illegal argument exception. When I use jpmml-r directly I get the same errors.

Decision tree example:
library(tree)
model <- tree(Species ~ Sepal.Width + Petal.Width, data = iris)
library(r2pmml)
r2pmml(model, "tree.pmml")
Oct 08, 2015 12:44:45 PM org.jpmml.rexp.Main run
INFO: Parsing ProtoBuf..
Oct 08, 2015 12:44:45 PM org.jpmml.rexp.Main run
INFO: Parsed ProtoBuf in 47 ms.
Oct 08, 2015 12:44:45 PM org.jpmml.rexp.Main run
INFO: Initializing default Converter
Error in .convert(tempfile, file, converter) :
java.lang.IllegalArgumentException

Linear regression:
cuse <- read.table("http://data.princeton.edu/wws509/datasets/cuse.dat", header=TRUE)
attach(cuse)
model <- glm( cbind(using, notUsing) ~ age + education + wantsMore , family = binomial)
library(r2pmml)
r2pmml(model, "glm.pmml")
Oct 08, 2015 12:55:42 PM org.jpmml.rexp.Main run
INFO: Parsing ProtoBuf..
Oct 08, 2015 12:55:42 PM org.jpmml.rexp.Main run
INFO: Parsed ProtoBuf in 41 ms.
Oct 08, 2015 12:55:42 PM org.jpmml.rexp.Main run
INFO: Initializing default Converter
Error in .convert(tempfile, file, converter) :
java.lang.IllegalArgumentException

Help appreciated. Cheers!
Ben.

Villu Ruusmann

unread,
Oct 9, 2015, 10:59:29 AM10/9/15
to Java PMML API
Hi Ben,

> I was trying the R exports today. While github example of the random forest
> with iris works, other models do not.
>

The list of supported R packages/model types can be found in the
README.md file, in section "Features".

>
> Decision tree example:
> library(tree)
> model <- tree(Species ~ Sepal.Width + Petal.Width, data = iris)

The "tree" model type is not supported.

> Linear regression:
> cuse <- read.table("http://data.princeton.edu/wws509/datasets/cuse.dat", header=TRUE)
> attach(cuse)
> model <- glm( cbind(using, notUsing) ~ age + education + wantsMore , family = binomial)

The "glm" model type is not supported. However, you can use the
standard R "pmml" package
(https://cran.r-project.org/web/packages/pmml) to convert glm model
objects to PMML.

Due to limited development resources, it would be pointless for the
JPMML-R project to re-invent stuff that is available by other means.
The support for randomForest model objects is an exception, because
the standard implementation has limited functionality (eg. does not
support RF models that are trained using the matrix interface) and is
extremely slow.


VR

Benjamin Auffarth

unread,
Oct 9, 2015, 11:33:19 AM10/9/15
to Villu Ruusmann, Java PMML API
Hi Villu, 
 thanks for the hint, appreciated. I am still learning. 

 I understand that it is impossible to support a large range of models mostly by yourself. However, I found it a bit confusing what is supported by r2pmml. It says: 

It supports several model types (eg. gbmtrain)

 So there are two supported packages, but then there's an "e.g." in front of it, so I was assuming it was supported a broader range of packages, particularly also because it mentions randomForest outside of the list. I had problems with exporting linear models using pmml (all the same values, see earlier message), so I tried your package. 

So, caret train is supported? That's really cool, but still I didn't get it to work with simple examples. 

library(caret)
model <- train(Sepal.Width ~ Species, data = iris, method = 'lm')
r2pmml(model$finalModel, '/tmp/lm.pmml')

 Oct 09, 2015 4:12:34 PM org.jpmml.rexp.Main run
INFO: Parsing ProtoBuf..
Oct 09, 2015 4:12:34 PM org.jpmml.rexp.Main run
INFO: Parsed ProtoBuf in 9 ms.
Oct 09, 2015 4:12:34 PM org.jpmml.rexp.Main run
INFO: Initializing default Converter
Oct 09, 2015 4:12:34 PM org.jpmml.rexp.Main run
INFO: Initialized org.jpmml.rexp.TrainConverter
Oct 09, 2015 4:12:34 PM org.jpmml.rexp.Main run
INFO: Converting model..
Oct 09, 2015 4:12:34 PM org.jpmml.rexp.Main run
SEVERE: Failed to convert model
java.lang.IllegalArgumentException
	at org.jpmml.rexp.ConverterFactory.newConverter(ConverterFactory.java:46)
	at org.jpmml.rexp.TrainConverter.convert(TrainConverter.java:31)
	at org.jpmml.rexp.Main.run(Main.java:146)

Error in .convert(tempfile, file, converter) : 
  java.lang.IllegalArgumentException


Cheers! 




----

Villu Ruusmann

unread,
Oct 9, 2015, 4:13:26 PM10/9/15
to Java PMML API
Hi Ben,

>
> So, caret train is supported? That's really cool, but still I didn't get it
> to work with simple examples.
>
> library(caret)
> model <- train(Sepal.Width ~ Species, data = iris, method = 'lm')
> r2pmml(model$finalModel, '/tmp/lm.pmml')
>

The "method" argument of the train() function call must correspond to
some supported model type. For example, you can use methods "rf" and
"gbm", but not "lm".

If you are looking for a comprehensive list of supported features,
then please see example R scripts:
https://github.com/jpmml/jpmml-r/tree/master/src/test/resources


VR

Hao Hu

unread,
Apr 10, 2016, 12:44:29 AM4/10/16
to Java PMML API
Dear Ruusmann,

My comany need to transform my gbm model to pmml format. I successfully intalled the package,
library(devtools)
install_github(repo = 'jpmml/r2pmml',force = TRUE)
library(r2pmml)
but when I tried run the example, I got an error,
options(warning.length = 2000) # 放宽报错显示内容长度限制
library("randomForest")
data(iris)
rf = randomForest(Species ~ ., data = iris, ntree = 7)
print(rf)
r2pmml(rf, "rf.pmml")
Error: can't find Files.R.R-3.1.2.library.r2pmml.java.guava-19.0.jar;C:.Program
Error in .convert(tempfile, file, ...) : 1
In addition: Warning message:
running command '"java" -cp C:/Program Files/R/R-3.1.2/library/r2pmml/java/guava-19.0.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/istack-commons-runtime-2.21.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/jaxb-core-2.2.11.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/jaxb-runtime-2.2.11.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/jcommander-1.48.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/jpmml-converter-1.0.3.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/jpmml-r-1.1.4.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/jpmml-xgboost-1.0.2.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/pmml-agent-1.2.11.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/pmml-model-1.2.11.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/pmml-model-metro-1.2.11.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/pmml-schema-1.2.11.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/slf4j-api-1.7.18.jar;C:/Program Files/R/R-3.1.2/library/r2pmml/java/slf4j-jdk14-1.7.18.jar org.jpmml.rexp.Main --rds-input C:\Users\qingyin.hh\AppData\Local\Temp\RtmpMLz6Ic\r2pmml-11904e64d33.rds --pmml-output rf.pmml' had status 1

could you tell me where I went wrong. Thanks for helping.

Villu Ruusmann

unread,
Apr 10, 2016, 6:06:48 AM4/10/16
to Java PMML API
Hi Hao,

>
> My comany need to transform my gbm model to pmml format. I successfully intalled the package,
> library(devtools)
> install_github(repo = 'jpmml/r2pmml',force = TRUE)
> library(r2pmml)
> but when I tried run the example, I got an error,
> Error: can't find Files.R.R-3.1.2.library.r2pmml.java.guava-19.0.jar;C:.Program
> Error in .convert(tempfile, file, ...) : 1
>

The r2pmml package builds the classpath string by concatenating the
paths of library JAR files. It was assumed that the resulting
classpath string is "contiguous" in a sense that it can be passed to
the command-line interpreter as it is.

However, your R installation is located under "C:/Program Files/R",
and the inclusion of 14 space characters into the classpath string
breaks the above assumption.

I have updated the r2pmml package so that it performs the quoting of
all file paths:
https://github.com/jpmml/r2pmml/commit/437e5e91b80753c050a28ebdd23543fdb3e5c4d6

If you re-install the r2pmml package, then everything should be good now:
remove.packages("r2pmml")
install_github(repo = "jpmml/r2pmml")


VR

Hao Hu

unread,
Apr 12, 2016, 8:19:15 PM4/12/16
to Java PMML API
great, it solves my problem. Thanks
Reply all
Reply to author
Forward
0 new messages