xgboost-native stable
Native XGBoost inference in pure Rust — no ONNX, no C++ runtime, runs anywhere Rust does. Reads XGBoost's native JSON format directly and implements inference and exact TreeSHAP without external dependencies.
Why
ONNX Runtime's C++ dependency is painful to cross-compile, bloats binaries, and has no support for platforms like FreeBSD. xgboost-native eliminates that entire dependency chain.
Capabilities
- Pure Rust inference — no C/C++ runtime, no FFI, no ONNX
- Exact TreeSHAP — per-feature explanations that sum to the raw margin
- Early stopping aware — respects
best_iterationfrom trained models - Cross-platform — compiles anywhere Rust does, including FreeBSD
- Minimal dependencies — only serde and thiserror
Usage
let model = xgboost_native::Model::load(Path::new("model.json"))?;
let prob = model.predict(&features);
let shap = model.shap(&features);
// sum(shap.values) + shap.bias ≈ model.raw_margin(&features)
Verification
Validated against XGBoost 3.2.0 (Python) and ort (ONNX Runtime) on held-out samples:
| Metric | Tolerance |
|---|---|
| Probability | < 1e-5 vs. Python, < 1e-4 vs. ort |
| Raw margin | < 1e-4 |
| SHAP values (per feature) | < 1e-3 |
Supported
binary:logistic objective, numeric splits, XGBoost native
JSON. No multi-class, no categorical splits.