Crates.io | lgbm-sys |
lib.rs | lgbm-sys |
version | 0.0.1 |
source | src |
created_at | 2023-06-16 11:42:06.229433 |
updated_at | 2023-06-16 11:42:06.229433 |
description | Unofficial Rust bindings for LightGBM |
homepage | |
repository | https://github.com/frozenlib/lgbm-rs |
max_upload_size | |
id | 892161 |
size | 79,714 |
Unofficial Rust bindings for LightGBM
LIGHTGBM_LIB_PATH
to the directory containing the build output (.dll
and .lib
on Windows, .so
on Linux).Run the following command to install LightGBM on your system.
brew install lightgbm
Cargo.toml
[dependencies]
lgbm = "0.0.1"
main.rs
use lgbm::{
parameters::{Objective, Verbosity},
Booster, Dataset, Field, Mat, Parameters, PredictType,
};
use std::sync::Arc;
fn main() -> anyhow::Result<()> {
let mut p = Parameters::new();
p.push("num_class", 3);
p.push("objective", Objective::Multiclass);
p.push("verbosity", Verbosity::Fatal);
let mut train = Dataset::from_mat(&Mat::from_rows(train_features()), None, &p)?;
train.set_field(Field::LABEL, &train_labels())?;
let mut valid = Dataset::from_mat(&Mat::from_rows(valid_features()), Some(&train), &p)?;
valid.set_field(Field::LABEL, &valid_labels())?;
let mut b = Booster::new(Arc::new(train), &p)?;
b.add_valid_data(Arc::new(valid))?;
for _ in 0..100 {
if b.update_one_iter()? {
break;
}
}
let p = Parameters::new();
let rs = b.predict_for_mat(
&Mat::from_rows(test_features()),
PredictType::Normal,
0,
None,
&p,
)?;
println!("\n{rs:.5}");
Ok(())
}
fn train_features() -> Vec<[f64; 1]> {
(0..128).map(|x| [(x % 3) as f64]).collect()
}
fn train_labels() -> Vec<f32> {
(0..128).map(|x| (x % 3) as f32).collect()
}
fn valid_features() -> Vec<[f64; 1]> {
(0..64).map(|x| [(x % 3) as f64]).collect()
}
fn valid_labels() -> Vec<f32> {
(0..64).map(|x| (x % 3) as f32).collect()
}
fn test_features() -> Vec<[f64; 1]> {
(0..4).map(|x| [(x % 3) as f64]).collect()
}
output
num_data : 4
num_class : 3
num_2 : 1
| 0 | 1 | 2 |
---|---------|---------|---------|
0 | 0.99998 | 0.00001 | 0.00001 |
1 | 0.00001 | 0.99998 | 0.00001 |
2 | 0.00001 | 0.00001 | 0.99998 |
3 | 0.99998 | 0.00001 | 0.00001 |
The following types of linking are supported.
os | static | dynamic |
---|---|---|
Windows | ✔ | ✔ |
Linux | ✔ | ✔ |
MacOS | ✔ |
On Windows, if lib_lightgbm.dll
exists in the directory specified by LIGHTGBM_LIB_PATH
, it will be dynamically linked. Otherwise, it will be statically linked.
On Linux, if lib_lightgbm.a
exists in the directory specified by LIGHTGBM_LIB_PATH
, it is statically linked. Otherwise, it is dynamically linked.
This project is licensed under MIT. See the LICENSE files for details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you will be under the MIT license, without any additional terms or conditions.