• Stars
    star
    338
  • Rank 124,931 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure Java implementation of XGBoost predictor for online prediction tasks.

xgboost-predictor-java

Build Status Download

Pure Java implementation of XGBoost predictor for online prediction tasks.

Getting started

Adding to dependencies

If you use Maven:

<repositories>
  <repository>
    <id>bintray-komiya-atsushi-maven</id>
    <url>http://dl.bintray.com/komiya-atsushi/maven</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>biz.k11i</groupId>
    <artifactId>xgboost-predictor</artifactId>
    <version>0.3.0</version>
  </dependency>
</dependencies>

Or Gradle:

repositories {
    // Use jcenter instead of mavenCentral
    jcenter()
}

dependencies {
    compile group: 'biz.k11i', name: 'xgboost-predictor', version: '0.3.0'
}

Or sbt:

resolvers += Resolver.jcenterRepo

libraryDependencies ++= Seq(
  "biz.k11i" % "xgboost-predictor" % "0.3.0"
)

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
    }
}

Apache Spark integration

See detail xgboost-predictor-spark.

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:squarederror"
    • "rank:pairwise"
  • API
    • Predicts probability or classification
      • Predictor#predict(FVec)
    • Outputs margin
      • Predictor#predict(FVec, true /* output margin */)
    • Predicts leaf index
      • Predictor#predictLeaf(FVec)

More Repositories

1

darts-java

Java porting of Darts (Double ARray Trie System)
Java
268
star
2

lz4-ruby

Ruby bindings for LZ4 (Extremely Fast Compression algorithm)
Ruby
65
star
3

markdown-previewer

Real-time Markdown & RDoc Previewer without any AJAX requests.
JavaScript
29
star
4

fast-rng-java

fast-rng: Fast random number generator for Java
Java
19
star
5

xor-filter

Production-ready Java implementation of the Xor Filter.
Java
17
star
6

node-marisa-trie

marisa-trie for Node.js
C++
11
star
7

snowflake-id

Twitter's Snowflake ID to Time conversion module
Ruby
8
star
8

bandit-simulator

Web-based bandit algorithm simulator
JavaScript
8
star
9

zipzop

Zip archive recompressor with Google's zopfli library.
C
8
star
10

typeorm-logger-adaptor

Logger adaptors for TypeORM
TypeScript
7
star
11

action-enforce-timeout-minutes

Enforces setting timeout-minutes of the workflow jobs to prevent waste of minutes quota.
TypeScript
5
star
12

jubaba-prototype

Java からの Jubatus の利用を楽にするためのラッパーライブラリ (プロトタイプ)
Java
5
star
13

xgboost-predictor-benchmark

Java
5
star
14

xgboost-dataframe-prototype

A prototype XGBoost integration with Spark and DataFrame (spark.ml)
Scala
4
star
15

java-playground

Playground of Java
Java
4
star
16

arow

A pure ruby implementation of the AROW
Ruby
3
star
17

stackdriver-friendly-json-logging-example

Sample code of the article: https://k11i.biz/blog/2018/10/03/stackdriver-logging-friendly-layout-java/
Java
2
star
18

dbflute-fes-2014-demo

DBFlute フェス 2014 ( http://connpass.com/event/9544/ ) の発表で利用したデモプログラム
Java
2
star
19

mllib-naivebayes-demo

Java
2
star
20

popcount-java-test

Java における各種 popcount 実装の性能比較をするためのプログラムです。
Java
2
star
21

ts-multipass

Shopify Multipass module for TypeScript.
TypeScript
1
star
22

winston-format-console-ootb

Winston formatter for console output out-of-the-box.
TypeScript
1
star
23

typescript-node-config-and-zod

An example of how to use node-config type safely
TypeScript
1
star
24

rapidhash-js

A TypeScript implementation of the rapidhash.
TypeScript
1
star
25

javajo-spark-ml-demo

A demo ML application using spark
Scala
1
star
26

gradle-scala-cross-build-demo

Cross-building Scala project using Gradle
Groovy
1
star
27

shibuya-java4

第4回 #渋谷java で発表したときのデモコードです。
Java
1
star
28

k11i-trie

Java implementation of Trie
Java
1
star
29

airflow-playground

Python
1
star
30

fast-loaded-dice-roller-java

Java implementation of the Fast Loaded Dice Roller
Java
1
star
31

sab-usage-detector

Detects usage of SharedArrayBuffer
TypeScript
1
star
32

croppng

Fast PNG cropping and resizing (upscaling) library
Java
1
star
33

slack-bolt-aws

AWS integrations for Bolt for JavaScript
TypeScript
1
star