xgboost-predictor

Pure Java implementation of XGBoost predictor for online prediction tasks

License

License

Categories

Categories

H2 Data Databases H2O Business Logic Libraries Machine Learning
GroupId

GroupId

ai.h2o
ArtifactId

ArtifactId

xgboost-predictor
Last Version

Last Version

0.3.18
Release Date

Release Date

Type

Type

jar
Description

Description

xgboost-predictor
Pure Java implementation of XGBoost predictor for online prediction tasks
Project URL

Project URL

https://github.com/h2oai/xgboost-predictor
Project Organization

Project Organization

H2O.ai
Source Code Management

Source Code Management

https://github.com/h2oai/xgboost-predictor

Download xgboost-predictor

How to add to project

<!-- https://jarcasting.com/artifacts/ai.h2o/xgboost-predictor/ -->
<dependency>
    <groupId>ai.h2o</groupId>
    <artifactId>xgboost-predictor</artifactId>
    <version>0.3.18</version>
</dependency>
// https://jarcasting.com/artifacts/ai.h2o/xgboost-predictor/
implementation 'ai.h2o:xgboost-predictor:0.3.18'
// https://jarcasting.com/artifacts/ai.h2o/xgboost-predictor/
implementation ("ai.h2o:xgboost-predictor:0.3.18")
'ai.h2o:xgboost-predictor:jar:0.3.18'
<dependency org="ai.h2o" name="xgboost-predictor" rev="0.3.18">
  <artifact name="xgboost-predictor" type="jar" />
</dependency>
@Grapes(
@Grab(group='ai.h2o', module='xgboost-predictor', version='0.3.18')
)
libraryDependencies += "ai.h2o" % "xgboost-predictor" % "0.3.18"
[ai.h2o/xgboost-predictor "0.3.18"]

Dependencies

compile (2)

Group / Artifact Type Version
ai.h2o : h2o-tree-api jar 0.3.18
net.jafama : jafama jar 2.1.0

Project Modules

There are no modules declared in this project.

xgboost-predictor-java

Maven Central

Pure Java implementation of XGBoost predictor for online prediction tasks.

Getting started

Adding to dependencies

If you use Maven:

<dependencies>
  <dependency>
    <groupId>ai.h2o</groupId>
    <artifactId>xgboost-predictor</artifactId>
    <version>0.3.1</version>
  </dependency>
</dependencies>

Or Gradle:

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'ai.h2o', name: 'xgboost-predictor', version: '0.3.1'
}

Or sbt:

resolvers += DefaultMavenRepository

libraryDependencies ++= Seq(
  "ai.h2o" % "xgboost-predictor" % "0.3.1"
)

Using Predictor in Java

package biz.k11i.xgboost.demo;

import biz.k11i.xgboost.Predictor;
import biz.k11i.xgboost.util.FVec;

public class HowToUseXgboostPredictor {
    public static void main(String[] args) throws java.io.IOException {
        // If you want to use faster exp() calculation, uncomment the line below
        // ObjFunction.useFastMathExp(true);

        // Load model and create Predictor
        Predictor predictor = new Predictor(
                new java.io.FileInputStream("/path/to/xgboost-model-file"));

        // Create feature vector from dense representation by array
        double[] denseArray = {0, 0, 32, 0, 0, 16, -8, 0, 0, 0};
        FVec fVecDense = FVec.Transformer.fromArray(
                denseArray,
                true /* treat zero element as N/A */);

        // Create feature vector from sparse representation by map
        FVec fVecSparse = FVec.Transformer.fromMap(
                new java.util.HashMap<Integer, Double>() {{
                    put(2, 32.);
                    put(5, 16.);
                    put(6, -8.);
                }});

        // Predict probability or classification
        double[] prediction = predictor.predict(fVecDense);

        // prediction[0] has
        //    - probability ("binary:logistic")
        //    - class label ("multi:softmax")

        // Predict leaf index of each tree
        int[] leafIndexes = predictor.predictLeaf(fVecDense);

        // leafIndexes[i] has a leaf index of i-th tree
    }
}

Benchmark

Throughput comparison to xgboost4j 1.1 by xgboost-predictor-benchmark.

Feature xgboost-predictor xgboost4j
Model loading 49017.60 ops/s 39669.36 ops/s
Single prediction 6016955.46 ops/s 1018.01 ops/s
Batch prediction 44985.71 ops/s 5.04 ops/s
Leaf prediction 11115853.34 ops/s 1076.54 ops/s

Xgboost-predictor-java is about 6,000 to 10,000 times faster than xgboost4j on prediction tasks.

Supported models, objective functions and API

  • Models
    • "gblinear"
    • "gbtree"
    • "dart"
  • Objective functions
    • "binary:logistic"
    • "binary:logitraw"
    • "multi:softmax"
    • "multi:softprob"
    • "reg:linear"
    • "reg:logistic"
    • "rank:pairwise"
    • "rank:ndcg"
  • API
    • Predicts probability or classification
      • Predictor#predict(FVec)
    • Outputs margin
      • Predictor#predict(FVec, true /* output margin */)
    • Predicts leaf index
      • Predictor#predictLeaf(FVec)
ai.h2o

H2O.ai

Fast Scalable Machine Learning For Smarter Applications

Versions

Version
0.3.18
0.3.17
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1