jpmml / r2pmml

R library for converting R models to PMML
GNU Affero General Public License v3.0
73 stars 18 forks source link

xgboost-0.6-0 convert failed #9

Closed pjpan closed 7 years ago

pjpan commented 7 years ago

xgboost version: 0.6-0


error message:

r2pmml(iris.xgb, fmap = iris.fmap, "iris_xgb.pmml") 九月 21, 2016 5:36:58 下午 org.jpmml.rexp.Main run 信息: Parsing RDS.. 九月 21, 2016 5:36:58 下午 org.jpmml.rexp.Main run 信息: Parsed RDS in 7 ms. 九月 21, 2016 5:36:58 下午 org.jpmml.rexp.Main run 信息: Initializing default Converter 九月 21, 2016 5:36:58 下午 org.jpmml.rexp.Main run 信息: Initialized org.jpmml.rexp.XGBoostConverter 九月 21, 2016 5:36:58 下午 org.jpmml.rexp.Main run 信息: Converting.. 九月 21, 2016 5:36:58 下午 org.jpmml.rexp.Main run 严重: Failed to convert java.lang.IllegalArgumentException: java.io.IOException at org.jpmml.rexp.XGBoostConverter.encodeModel(XGBoostConverter.java:90) at org.jpmml.rexp.XGBoostConverter.encodeModel(XGBoostConverter.java:40) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:90) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:74) at org.jpmml.rexp.Main.run(Main.java:149) at org.jpmml.rexp.Main.main(Main.java:97) Caused by: java.io.IOException at org.jpmml.xgboost.XGBoostDataInput.readReserved(XGBoostDataInput.java:68) at org.jpmml.xgboost.Learner.load(Learner.java:59) at org.jpmml.xgboost.XGBoostUtil.loadLearner(XGBoostUtil.java:34) at org.jpmml.rexp.XGBoostConverter.loadLearner(XGBoostConverter.java:159) at org.jpmml.rexp.XGBoostConverter.encodeModel(XGBoostConverter.java:88) ... 5 more

Exception in thread "main" java.lang.IllegalArgumentException: java.io.IOException at org.jpmml.rexp.XGBoostConverter.encodeModel(XGBoostConverter.java:90) at org.jpmml.rexp.XGBoostConverter.encodeModel(XGBoostConverter.java:40) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:90) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:74) at org.jpmml.rexp.Main.run(Main.java:149) at org.jpmml.rexp.Main.main(Main.java:97) Caused by: java.io.IOException at org.jpmml.xgboost.XGBoostDataInput.readReserved(XGBoostDataInput.java:68) at org.jpmml.xgboost.Learner.load(Learner.java:59) at org.jpmml.xgboost.XGBoostUtil.loadLearner(XGBoostUtil.java:34) at org.jpmml.rexp.XGBoostConverter.loadLearner(XGBoostConverter.java:159) at org.jpmml.rexp.XGBoostConverter.encodeModel(XGBoostConverter.java:88) ... 5 more Picked up _JAVA_OPTIONS: -Xmx16G Error in .convert(tempfile, file, ...) : 1 In addition: Warning message: running command '"java" -cp "C:/Program Files/R/R-3.3.1/library/r2pmml/java/guava-19.0.jar;"

R code,just use your example;

library("xgboost") library("r2pmml") data(iris) iris_x = iris[, 1:4] iris_y = as.integer(iris[, 5]) - 1

Train a model

iris.xgb = xgboost(data = as.matrix(iris_x), label = iris_y, objective = "multi:softmax", num_class = 3, nrounds = 13)

Create a feature map

iris.fmap = data.frame( "id" = seq(from = 0, (to = ncol(iris_x) - 1)), "name" = names(iris_x), "type" = rep("q", ncol(iris_x)) )

Export the model to PMML.

Pass the feature map as the fmap argument

r2pmml(iris.xgb, fmap = iris.fmap, "iris_xgb.pmml")

vruusmann commented 7 years ago

This issue has been fixed in the JPMML-XGBoost library: https://github.com/jpmml/jpmml-xgboost/commit/ec4bdc669d625dabb34fd63ae24f516d1092428c

pjpan commented 7 years ago

thanks,it solved the problem.

AlexYoung757 commented 7 years ago

@vruusmann why can't directly use function r2pmml to save the train model ,such as r2pmml(iris.xgb, fmap = iris.fmap, "iris_xgb.pmml")

vruusmann commented 7 years ago

why can't directly use function r2pmml to save the train model

@AlexYoung757 Why can't you, is there some sort of exception being thrown?

Please note that the ordering or parameters has changed in recent r2pmml package versions. You need to specify the name of the output PMML file as the second argument, and the feature map as the third argument:

r2pmml(iris.xgb, "iris_xgb.pmml", fmap = iris.fmap)
AlexYoung757 commented 7 years ago

@vruusmann thank you . I update the latest version , it can works well