Elvenson / xgboost-go

XGBoost inference with Golang.
MIT License
25 stars 5 forks source link

xgboost-go

Build Status GoDoc

XGBoost inference with Golang by means of exporting xgboost model into json format and load model from that json file. This repo only supports DMLC XGBoost model at the moment. For more information regarding how XGBoost inference works, you can refer to this medium article.

Features

Currently, this repo only supports a few core features such as:

NOTE: The result from DMLC XGBoost model may slightly differ from this model due to float number precision.

How to use:

To use this repo, first you need to get it:

go get github.com/Elvenson/xgboost-go

Basic example:

package main

import (
    "fmt"

    xgb "github.com/Elvenson/xgboost-go"
    "github.com/Elvenson/xgboost-go/activation"
    "github.com/Elvenson/xgboost-go/mat"
)

func main() {
    ensemble, err := xgb.LoadXGBoostFromJSON("your model path",
        "", 1, 4, &activation.Logistic{})
    if err != nil {
        panic(err)
    }

    input, err := mat.ReadLibsvmFileToSparseMatrix("your libsvm input path")
    if err != nil {
        panic(err)
    }
    predictions, err := ensemble.PredictProba(input)
    if err != nil {
        panic(err)
    }
    fmt.Printf("%+v\n", predictions)
}

Here LoadXGBoostFromJSON requires 5 parameters:

For more example, can take a look at xgbensemble_test.go or read this package documentation.

NOTE: This repo only got tested on Python xgboost package version 1.2.0.

Contribution:

All contributions are welcome. Before submitting a pull request, we first need to format the code using the following command:

make fmt

Then run the following command to check if everything is good:

make ci