Skip to content

Java library and command-line application for converting XGBoost models to PMML

License

Notifications You must be signed in to change notification settings

buildhappy/jpmml-xgboost

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JPMML-XGBoost

Java library and command-line application for converting XGBoost models to PMML.

Prerequisites

  • Java 1.8 or newer.

Installation

Enter the project root directory and build using Apache Maven:

mvn clean install

The build produces an executable uber-JAR file target/jpmml-xgboost-executable-1.3-SNAPSHOT.jar.

Usage

A typical workflow can be summarized as follows:

  1. Use XGBoost to train a model.
  2. Save the model and the associated feature map to files in a local filesystem.
  3. Use the JPMML-XGBoost command-line converter application to turn those two files to a PMML file.

The XGBoost side of operations

Using r2pmml and xgboost packages to train a linear regression model for the example mtcars dataset:

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)

mpg_y = mtcars[, 1]
mpg_X = mtcars[, 2:ncol(mtcars)]

# Generate feature map
mpg.fmap = r2pmml::genFMap(mpg_X)
r2pmml::writeFMap(mpg.fmap, "xgboost.fmap")

# Generate DMatrix
mpg.dmatrix = r2pmml::genDMatrix(mpg_y, mpg_X, "xgboost.svm")

set.seed(31)

# Train a linear regression model
mpg.xgb = xgboost(data = mpg.dmatrix, objective = "reg:linear", nrounds = 7)

# Save the model in XGBoost proprietary binary format
xgb.save(mpg.xgb, "xgboost.model")

# Dump the model in text format
xgb.dump(mpg.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 xgboost.pmml:

java -jar target/jpmml-xgboost-executable-1.3-SNAPSHOT.jar --model-input xgboost.model --fmap-input xgboost.fmap --target-name mpg --pmml-output xgboost.pmml

Getting help:

java -jar target/jpmml-xgboost-executable-1.3-SNAPSHOT.jar --help

License

JPMML-XGBoost is dual-licensed under the GNU Affero General Public License (AGPL) version 3.0, and a commercial license.

Additional information

JPMML-XGBoost is developed and maintained by Openscoring Ltd, Estonia.

Interested in using JPMML software in your application? Please contact [email protected]

About

Java library and command-line application for converting XGBoost models to PMML

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 88.9%
  • R 11.1%