CatBoost is a popular open-source library for gradient boosting on decision trees.
go-catboost is an attempt to create a portable pure-Go implementation of the CatBoost tree evaluation logic, for environments where using cgo bindings is not possible or desirable.
Check out examples and godoc.md.
Proof-of-concept. Works on test models and test inputs, but not battle-tested. API may change without a warning.
- Only json (and json.gz) model formats are supported. Export with
save_model(..., format="json")or use cbm2json.py to convert. - Only float and categorical (one-hot and ctr) features are supported.
- Likely noticably slower (especially on large batches) than C++ core.
A SIMD-accelerated path is available on AMD64 with Go 1.26 and GOEXPERIMENT=simd enabled (via experimental simd/archsimd package).
The correctness is verified against the Python catboost library across various model configurations using randomized inputs (gentestdata.py). Note that the result may differ by 1-2 ULPs depending on the platform due to floating-point arithmetic differences between Go and libc. Tests are written to tolerate that.
The work is largely based on Explanation of Json model format of CatBoost article by Paras Malik with heavy reference to the CatBoost C++ source code. Parts of the project are either a direct port or a reimplementation of the code that can be found in:
catboost/libs/model/cpu/evaluator_impl.cpp- oblivious & non-symmetric tree evaluationcatboost/libs/model/eval_processing.h- prediction types handlingcatboost/libs/model/model.h- model and tree structscatboost/libs/model/model_export/resources/ctr_calcer.cpp- ctr value computationcatboost/libs/model/online_ctr.h- ctr formulacatboost/libs/cat_feature/cat_feature.cpp- cat feature hashingutil/digest/city.cpp- CityHash implementation