6个稳定版本

1.0.5 2024年8月15日
1.0.3 2024年8月10日
1.0.2 2023年7月19日
1.0.1 2023年6月30日
1.0.0 2023年6月24日

#54 in 机器学习

Download history 2/week @ 2024-05-20 68/week @ 2024-07-22 37/week @ 2024-07-29 109/week @ 2024-08-05 239/week @ 2024-08-12

453 每月下载量

MIT 许可证

9MB
177K SLoC

C++ 104K SLoC // 0.1% comments FORTRAN Legacy 23K SLoC // 0.4% comments Python 18K SLoC // 0.2% comments R 12K SLoC // 0.2% comments CUDA 11K SLoC // 0.1% comments C 4K SLoC // 0.4% comments Shell 2K SLoC // 0.2% comments Rust 1K SLoC // 0.0% comments PowerShell 402 SLoC // 0.1% comments SWIG 399 SLoC // 0.3% comments Visual Studio Project 351 SLoC JavaScript 260 SLoC // 0.1% comments XSL 115 SLoC Visual Studio Solution 32 SLoC Bazel 27 SLoC Batch 27 SLoC Bitbake 8 SLoC Forge Config 3 SLoC

lightgbm3 — Rust语言绑定库LightGBM

Crates.io Docs.rs build

lightgbm3 基于 lightgbm (目前已不再支持),但它与之不兼容。

安装

cargo add lightgbm3

由于 lightgbm3 从源代码编译 LightGBM,因此您还需要安装开发库

Linux

apt install -y cmake clang libclang-dev libc++-dev gcc-multilib

Mac

brew install cmake
brew install libomp # only required if you compile with "openmp" feature

Windows

  1. 安装CMake和VS构建工具。
  2. 安装LLVM并设置环境变量 LIBCLANG_PATH(例如 C:\Program Files\LLVM\bin

请参阅以下详细信息。

使用

训练

use lightgbm3::{Dataset, Booster};
use serde_json::json;

let features = vec![vec![1.0, 0.1, 0.2],
                    vec![0.7, 0.4, 0.5],
                    vec![0.9, 0.8, 0.5],
                    vec![0.2, 0.2, 0.8],
                    vec![0.1, 0.7, 1.0]];
let labels = vec![0.0, 0.0, 0.0, 1.0, 1.0];
let dataset = Dataset::from_vec_of_vec(features, labels, true).unwrap();
let params = json!{
   {
        "num_iterations": 10,
        "objective": "binary",
        "metric": "auc",
    }
};
let bst = Booster::train(dataset, &params).unwrap();
bst.save_file("path/to/model.lgb").unwrap();

推理

use lightgbm3::{Dataset, Booster};

let bst = Booster::from_file("path/to/model.lgb").unwrap();
let features = vec![1.0, 2.0, -5.0];
let n_features = features.len();
let y_pred = bst.predict_with_params(&features, n_features as i32, true, "num_threads=1").unwrap()[0];

更多信息请查看 ./examples/ 文件夹

功能

lightgbm3 支持以下功能

  • polars 支持 polars
  • openmp 支持 MPI
  • gpu 支持 GPU
  • cuda 支持实验性的 CUDA

基准测试

cargo bench

相应地添加 --features=openmp--features=gpu--features=cuda

开发

git clone --recursive https://github.com/Mottl/lightgbm3-rs.git

感谢

vaaaaanquish 的 LightGBM Rust 包表示敬意,遗憾的是它已不再支持。

参考了实现和文档。感谢。

依赖项

~0.8–14MB
~166K SLoC