Skip to main content

Crate hessboost

Crate hessboost 

Source
Expand description

§hessboost

A faithful, fast, pure-Rust reimplementation of XGBoost gradient boosting with no C/C++ dependency and no FFI.

§Quick start

Build a DMatrix, configure TrainingParams with a builder, call train, then predict:

use hessboost::prelude::*;

// 6 rows × 2 features, row-major, plus a label per row.
let x = [0.0, 0.0,  1.0, 0.0,  0.0, 1.0,  1.0, 1.0,  0.5, 0.5,  0.2, 0.9];
let y = [0.0,       1.0,       1.0,       0.0,       0.5,       0.7];
let dtrain = DMatrix::from_dense(&x, 6, 2)?.with_labels(&y)?;

let params = TrainingParams::builder()
    .objective("reg:squarederror") // XGBoost-compatible names
    .tree_method(TreeMethod::Hist)
    .max_depth(3)
    .eta(0.1)
    .build()?;

let model = train(&params, &dtrain, 50)?;
let preds = model.predict(&dtrain)?;
assert_eq!(preds.len(), 6);

model.save_binary("model.bin")?;      // native format

§What’s here

  • Boosters: gbtree, dart, gblinear.
  • Tree methods: exact, hist, and approx, with depthwise or lossguide growth.
  • Objectives: regression, binary/multiclass classification, count (poisson/gamma/tweedie), learning-to-rank (LambdaMART), and a custom hook (train_with_objective).
  • Metrics: rmse, mae, logloss, error, auc, aucpr, mlogloss, merror, ndcg/map, nloglik, and a custom hook (train_with_custom_metric).
  • Modeling: monotone & interaction constraints, native categorical splits, early stopping, feature importance, TreeSHAP contributions and interaction values (BoostedModel::predict_contribs / predict_interactions).
  • I/O: libsvm/CSV loaders, native binary + JSON model I/O, and XGBoost-format JSON model import/export (crate::model).
  • Validation: cross-validation (cv).

§Where to look

§Compatibility notes

Objective, metric, and parameter names mirror XGBoost, so configurations transfer directly. Predictions match XGBoost’s model quality (parity is CI-tested) but are not bit-identical. The two histogram implementations pick slightly different split points.

Modules§

booster
Non-tree boosters.
config
Training configuration types.
data
Dataset containers, metadata, and loaders.
error
Error types for hessboost.
learner
Top-level orchestration: the boosting loop, the trained model, prediction, and feature importance.
metric
Evaluation metrics used for reporting and early stopping.
model
Cross-tool model interchange.
objective
Learning objectives: gradients, Hessians, prediction transforms, and base score estimation.
prelude
Commonly used imports include use hessboost::prelude::*;.
tree
Decision-tree representation, split-scoring math, and construction.