Skip to main content

Crate nanogbm

Crate nanogbm 

Source
Expand description

A small, pure-Rust gradient boosting library with a deliberately narrow scope: GBDT only, binary classification only, CPU only, dense numerical features. No DART/GOSS/RF, no multiclass, no ranking, no regression, no sparse inputs, no GPU, no FFI bindings.

§Quickstart

Declare your features as named closures over your own row type, then train and predict by handing the same FeatureBuilder to both sides.

use nanogbm::{Config, FeatureBuilder, GbdtTrainer};

struct Row { age: f64, income: f64, active: bool }

let cfg = Config {
    num_iterations: 100,
    learning_rate: 0.1,
    num_leaves: 31,
    ..Config::default()
};

let fb = FeatureBuilder::<Row>::new()
    .add_continuous("age", |r| r.age)
    .add_continuous("income", |r| r.income)
    .add_boolean("active", |r| r.active);

let model = GbdtTrainer::new(&cfg, &fb).fit(&rows, &labels, None)?;
let probs = model.predict_proba(&fb, &rows);

§Highlights

  • Histogram learner with sibling-by-subtraction.
  • Missing values handled at the split (NaN bucket, per-node direction by gain).
  • Early stopping truncates the model to the best iteration.
  • Deterministic: same Config + same data → byte-identical model. All randomness flows through a single ChaCha8Rng seeded from Config::seed.
  • Bincode v2 + serde serialization of Model.

See the examples/ directory for runnable end-to-end programs.

Re-exports§

pub use boosting::GbdtTrainer;
pub use config::Config;
pub use dataset::Dataset;
pub use error::Error;
pub use error::Result;
pub use feature::FeatureBuilder;
pub use model::Model;

Modules§

boosting
config
dataset
error
feature
Declarative feature extraction.
loss
Binary logistic loss: sigmoid, init score, packed gradients/hessians, and the binary logloss evaluation metric. One file because the project is scope-locked to binary classification.
model
tree