MCPcopy Index your code
hub / github.com/Elvenson/xgboost-go

github.com/Elvenson/xgboost-go @v0.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.4 ↗ · + Follow
62 symbols 201 edges 16 files 35 documented · 56%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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:

  • Read models from json format file (via dump_model API call)
  • Support sigmoid and softmax transformation activation.
  • Support binary and multiclass predictions.
  • Support regressions predictions.
  • Support missing values.
  • Support libsvm data format.

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: ```shell script go get github.com/Elvenson/xgboost-go


Basic example:

```go
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: * The json model path. * DMLC feature map format, if no feature map leave this blank. * The number of classes (if this is a binary classification, the number of classes should be 1) * The depth of the tree, if unable to get the tree depth can specify 0 (slightly slower model built time) * Activation function, for now binary is Logistic multiclass is Softmax and regression is Raw.

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.

Extension points exported contracts — how you extend this code

Activation (Interface)
Activation is an interface that an activation needs to implement. [3 implementers]
activation/common.go
EnsembleBase (Interface)
EnsembleBase contains interface of a base model. [1 implementers]
inference/inference.go

Core symbols most depended-on inside this repo

IsEqualMatrices
called by 19
mat/mat.go
NumClasses
called by 11
inference/inference.go
PredictProba
called by 10
inference/inference.go
LoadXGBoostFromJSON
called by 8
xgbensembleio.go
ReadCSVFileToDenseMatrix
called by 7
mat/mat.go
Predict
called by 7
inference/inference.go
predict
called by 6
xgbtree.go
ReadLibsvmFileToSparseMatrix
called by 6
mat/mat.go

Shape

Method 25
Function 22
Struct 10
TypeAlias 3
Interface 2

Languages

Go98%
Python2%

Modules by API surface

mat/mat.go9 symbols
inference/inference.go9 symbols
xgbensembleio.go7 symbols
xgbensemble_test.go5 symbols
activation/softmax.go5 symbols
activation/logistic.go5 symbols
xgbensemble.go4 symbols
protobuf/activation.pb.go4 symbols
activation/raw.go4 symbols
activation/common.go4 symbols
xgbtree.go3 symbols
mat/mat_test.go2 symbols

For agents

$ claude mcp add xgboost-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page