LightGBM Rust binding
This is an opinionated fork of vaaaaanquish/lightgbm-rs to fit needs at DeepSignSecurity. Generally we try to first offer fixes as PR to upstream, before merging them into main
here. Exceptions apply for changes vaaaaanquish has already expressed no interest in, or that depend on other changes upstream hasn't accepted yet.
List of changes in main
:
- Merge vaaaaanquish#35 (Fix truncated feature names)
- Merge vaaaaanquish#36 (add save_file_size api)
- Merge vaaaaanquish#37 (add load_string and save_string apis)
- Merge vaaaaanquish#43 (Set weights, but with more sanity checks and unit tests)
- Switch to upstream microsoft/lightgbm
- Merge vaaaaanquish#44 (configure C++11 even more explicitly as suggested in vaaaaanquish#40)
You need an environment that can build LightGBM.
# linux
apt install -y cmake libclang-dev libc++-dev gcc-multilib
# OS X
brew install cmake libomp
On Windows
- Install CMake and VS Build Tools.
- Install LLVM and set an environment variable
LIBCLANG_PATH
to PATH_TO_LLVM_BINARY (example:C:\Program Files\LLVM\bin
)
Please see below for details.
Example LightGBM train.
extern crate serde_json;
use lightgbm::{Dataset, Booster};
use serde_json::json;
let data = vec![vec![1.0, 0.1, 0.2, 0.1],
vec![0.7, 0.4, 0.5, 0.1],
vec![0.9, 0.8, 0.5, 0.1],
vec![0.2, 0.2, 0.8, 0.7],
vec![0.1, 0.7, 1.0, 0.9]];
let label = vec![0.0, 0.0, 0.0, 1.0, 1.0];
let dataset = Dataset::from_mat(data, label).unwrap();
let params = json!{
{
"num_iterations": 3,
"objective": "binary",
"metric": "auc"
}
};
let bst = Booster::train(dataset, ¶ms).unwrap();
Please see the ./examples
for details.
example | link |
---|---|
binary classification | link |
multiclass classification | link |
regression | link |
git clone --recursive https://github.com/vaaaaanquish/lightgbm-rs
docker build -t lgbmrs .
docker run -it -v $PWD:/app lgbmrs bash
# cargo build
Much reference was made to implementation and documentation. Thanks.