rust-xgboost
This is mostly a fork of https://github.com/davechallis/rust-xgboost but uses
another xgboost version and links it dynamically instead of linkit it static as the original library.
Rust bindings for the XGBoost gradient boosting library.
Creates a shared library and uses Ninja instead of makefiles as generator.
Requirements
brew commands for MacOs:
- brew install cmake
- brew install ninja
- brew install llvm
- brew install libomp
Documentation
Basic usage example:
extern crate xgb;
use xgb::{parameters, DMatrix, Booster};
fn main() {
let x_train = &[1.0, 1.0, 1.0,
1.0, 1.0, 0.0,
1.0, 1.0, 1.0,
0.0, 0.0, 0.0,
1.0, 1.0, 1.0];
let num_rows = 5;
let y_train = &[1.0, 1.0, 1.0, 0.0, 1.0];
let mut dtrain = DMatrix::from_dense(x_train, num_rows).unwrap();
dtrain.set_labels(y_train).unwrap();
let x_test = &[0.7, 0.9, 0.6];
let num_rows = 1;
let y_test = &[1.0];
let mut dtest = DMatrix::from_dense(x_test, num_rows).unwrap();
dtest.set_labels(y_test).unwrap();
let learning_params = parameters::learning::LearningTaskParametersBuilder::default()
.objective(parameters::learning::Objective::BinaryLogistic)
.build().unwrap();
let tree_params = parameters::tree::TreeBoosterParametersBuilder::default()
.max_depth(2)
.eta(1.0)
.build().unwrap();
let booster_params = parameters::BoosterParametersBuilder::default()
.booster_type(parameters::BoosterType::Tree(tree_params))
.learning_params(learning_params)
.verbose(true)
.build().unwrap();
let evaluation_sets = &[(&dtrain, "train"), (&dtest, "test")];
let params = parameters::TrainingParametersBuilder::default()
.dtrain(&dtrain) .boost_rounds(2) .booster_params(booster_params) .evaluation_sets(Some(evaluation_sets)) .build().unwrap();
let bst = Booster::train(¶ms).unwrap();
println!("{:?}", bst.predict(&dtest).unwrap());
}
See the examples directory for
more detailed examples of different features.
Status
Currently in a very early stage of development, so the API is changing as usability issues occur,
or new features are supported.
If you build it locally, after cloning, perform git submodule update --init --recursive
to install submodule dependencies.s
Builds against XGBoost 3.0.0.
Deactivated tests - functions probably not working correctly:
- booster::dump_model
- dmatrix::get_set_base_margin
- dmatrix::get_set_group
- dmatrix::get_set_weights
Platforms
Tested:
Untested: