Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

README.md

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.4-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 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)

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 xgboost.pmml:

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

Getting help:

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

Documentation

License

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.

Additional information

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

Interested in using Java PMML API software in your company? Please contact info@openscoring.io

About

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

Resources

License

You can’t perform that action at this time.