forked fromdavechallis/rust-xgboost
- Notifications
You must be signed in to change notification settings - Fork7
postgresml/rust-xgboost
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Rust bindings for theXGBoost gradient boosting library.
- Clang v16.0.0
Basic usage example:
externcrate xgboost;use xgboost::{parameters,DMatrix,Booster};fnmain(){// training matrix with 5 training examples and 3 featureslet 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];// convert training data into XGBoost's matrix formatletmut dtrain =DMatrix::from_dense(x_train, num_rows).unwrap();// set ground truth labels for the training matrix dtrain.set_labels(y_train).unwrap();// test matrix with 1 rowlet x_test =&[0.7,0.9,0.6];let num_rows =1;let y_test =&[1.0];letmut dtest =DMatrix::from_dense(x_test, num_rows).unwrap(); dtest.set_labels(y_test).unwrap();// configure objectives, metrics, etc.let learning_params = parameters::learning::LearningTaskParametersBuilder::default().objective(parameters::learning::Objective::BinaryLogistic).build().unwrap();// configure the tree-based learning model's parameterslet tree_params = parameters::tree::TreeBoosterParametersBuilder::default().max_depth(2).eta(1.0).build().unwrap();// overall configuration for Boosterlet booster_params = parameters::BoosterParametersBuilder::default().booster_type(parameters::BoosterType::Tree(tree_params)).learning_params(learning_params).verbose(true).build().unwrap();// specify datasets to evaluate against during traininglet evaluation_sets =&[(&dtrain,"train"),(&dtest,"test")];// overall configuration for training/evaluationlet params = parameters::TrainingParametersBuilder::default().dtrain(&dtrain)// dataset to train with.boost_rounds(2)// number of training iterations.booster_params(booster_params)// model parameters.evaluation_sets(Some(evaluation_sets))// optional datasets to evaluate against in each iteration.build().unwrap();// train model, and print evaluation datalet bst =Booster::train(¶ms).unwrap();println!("{:?}", bst.predict(&dtest).unwrap());}
See theexamples directory formore detailed examples of different features.
Currently in a very early stage of development, so the API is changing as usability issues occur,or new features are supported.
Builds against XGBoost 2.0.3.
Tested:
- Linux
- Mac OS
Unsupported:
- Windows
About
Rust bindings for XGBoost.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Languages
- Rust100.0%