Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
CatBoost Rust Bindings
Rust bindings for CatBoost, a gradient boosting library for machine learning. This crate provides a safe and ergonomic Rust interface to CatBoost's C API.
Features
- Cross-platform: Works on Linux, macOS, and Windows
- Self-contained: Downloads CatBoost binaries at runtime - no system dependencies required
- Version control: Specify different CatBoost versions via environment variable
- Safe Rust API: Memory-safe wrapper around CatBoost's C API
- Multiple feature types: Support for numeric, categorical, text, and embedding features
- GPU support: Optional GPU acceleration (requires
gpufeature)
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
For GPU support:
[]
= { = "0.2.0", = ["gpu"] }
Quick Start
use ;
Usage Examples
Basic Usage
use ;
// Load model from file
let model = load?;
// Simple numeric features prediction
let features = new
.with_float_features;
let predictions = model.predict?;
Categorical Features
use ;
let model = load?;
// Mixed numeric and categorical features
let features = new
.with_float_features
.with_cat_features;
let predictions = model.predict?;
Text Features
use ;
use CString;
let model = load?;
let text_features = vec!;
let features = new
.with_float_features
.with_text_features;
let predictions = model.predict?;
Embedding Features
use ;
let model = load?;
let embeddings = vec!;
let features = new
.with_float_features
.with_embedding_features;
let predictions = model.predict?;
Zero-Copy Buffer Loading (Recommended)
Model::load_buffer_zero_copy is the recommended way to load models from memory. Unlike load_buffer, it avoids copying the model data, resulting in lower memory usage, faster loading, and no internal memory pool leaks. Requires CatBoost v1.2.9+ (the default).
use Model;
use fs;
let buffer = read?;
let model = load_buffer_zero_copy?;
The buffer is owned by the Model and freed automatically when it is dropped.
Configuration
CatBoost Version
You can specify which version of CatBoost to use by setting the CATBOOST_VERSION environment variable:
The default version is 1.2.8.
GPU Support
To enable GPU acceleration, compile with the gpu feature:
Then enable GPU evaluation in your code:
let model = load?;
model.enable_gpu_evaluation?;
Model Information
You can inspect model properties:
let model = load?;
println!;
println!;
println!;
println!;
println!;
println!;
Error Handling
The crate provides comprehensive error handling:
use ;
match load_and_predict
Platform Support
This crate automatically downloads the appropriate CatBoost binary for your platform:
- Linux: x86_64, aarch64
- macOS: Universal binary (x86_64 + arm64)
- Windows: x86_64
Building from Source
The crate downloads CatBoost binaries at runtime, so no system dependencies are required. However, if you want to build from source, you can set the CATBOOST_BUILD_FROM_SOURCE environment variable.
License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Examples
See the examples/ directory for more detailed usage examples:
basic_usage.rs- Simple prediction examplesadvanced_usage.rs- Advanced features and model inspection
Run examples with: