Java library and command-line application for converting XGBoost models to PMML.
- Java 1.8 or newer.
Enter the project root directory and build using Apache Maven:
mvn clean install
The build produces an executable uber-JAR file
A typical workflow can be summarized as follows:
- Use XGBoost to train a model.
- Save the model and the associated feature map to files in a local filesystem.
- Use the JPMML-XGBoost command-line converter application to turn those two files to a PMML file.
The XGBoost side of operations
library("r2pmml") library("xgboost") data(mtcars) # Convert selected columns from numeric datatype to integer or factor datatypes mtcars$cyl = as.integer(mtcars$cyl) mtcars$vs = as.factor(mtcars$vs) mtcars$am = as.factor(mtcars$am) mtcars$gear = as.integer(mtcars$gear) mtcars$carb = as.integer(mtcars$carb) mtcars_y = mtcars[, 1] mtcars_X = mtcars[, 2:ncol(mtcars)] mtcars.formula = formula(~ . - 1) mtcars.frame = model.frame(mtcars.formula, data = mtcars_X) mtcars.matrix = model.matrix(mtcars.formula, data = mtcars.frame) # Generate feature map mtcars.fmap = as.fmap(mtcars.frame) write.fmap(mtcars.fmap, "xgboost.fmap") # Generate DMatrix mtcars.dmatrix = xgb.DMatrix(data = mtcars.matrix, label = mtcars_y) set.seed(31) # Train a linear regression model mtcars.xgb = xgboost(data = mtcars.dmatrix, objective = "reg:squarederror", nrounds = 17) # Save the model in XGBoost proprietary binary format xgb.save(mtcars.xgb, "xgboost.model") # Dump the model in text format xgb.dump(mtcars.xgb, "xgboost.model.txt", fmap = "xgboost.fmap")
The JPMML-XGBoost side of operations
Converting the model file
xgboost.model together with the associated feature map file
xgboost.fmap to a PMML file
java -jar target/jpmml-xgboost-executable-1.4-SNAPSHOT.jar --model-input xgboost.model --fmap-input xgboost.fmap --target-name mpg --pmml-output xgboost.pmml
java -jar target/jpmml-xgboost-executable-1.4-SNAPSHOT.jar --help
- Stacking Scikit-Learn, LightGBM and XGBoost models
- Extending Scikit-Learn with GBDT plus LR ensemble (GBDT+LR) model type (Using XGBoost models on the GBDT side of GBDT+LR ensemble)
JPMML-XGBoost is licensed under the terms and conditions of the GNU Affero General Public License, Version 3.0.
If you would like to use JPMML-XGBoost in a proprietary software project, then it is possible to enter into a licensing agreement which makes JPMML-XGBoost available under the terms and conditions of the BSD 3-Clause License instead.
JPMML-XGBoost is developed and maintained by Openscoring Ltd, Estonia.