lightgbm3 - Rust (original) (raw)

Expand description

LightGBM Rust library

lightgbm3 supports the following features:

§Examples

§Training:

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();

§Inference:

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];

Booster

Core model in LightGBM, containing functions for training, evaluating and predicting.

Dataset

LightGBM Dataset

Error

Wrap errors returned by the LightGBM library.

ImportanceType

Type of feature importance

DType

LightGBM dtype

argmax

Get index of the element in a slice with the maximum value

Result

Convenience return type for most operations which can return an LightGBM.