RustyML
A machine learning and deep learning library written in pure Rust.
Read the RustyML User Guide for instructions and examples.
Overview
RustyML provides data preprocessing, machine learning models, neural networks, and evaluation metrics.
It uses ndarray arrays and Rust numeric kernels.
Features
- Parallel kernels: selected kernels use Rayon. Work thresholds control the choice between serial and parallel paths.
- Models: supervised learning, unsupervised learning, anomaly detection, sequential networks, and graph networks.
- Random seeds:
set_global_seedsets a seed stream on the calling thread. Localrandom_statevalues override that stream where supported. - Binary files: supported models use Serde and postcard to save and load fitted state.
- Network checkpoints: save model arrays, then load them into a compatible built model. Checkpoints do not restore the optimizer or loss.
- Metrics: regression, binary classification, multiclass classification, and clustering. Read each metric's input rules and score definition.
Reset the global seed before repeating the same sequence of random operations. Other threads have separate seed streams. Some decomposition solvers use independent seeds.
Installation
Add RustyML to your Cargo.toml:
[]
= "0.17.0"
= "0.17"
Disable default features to select individual modules:
# Everything (ml, nn, utils, metrics, math)
= "0.17.0"
# Just the neural-network framework
= { = "0.17.0", = false, = ["neural_network"] }
# Just the evaluation metrics
= { = "0.17.0", = false, = ["metrics"] }
# Show training progress bars in the terminal
= { = "0.17.0", = ["show_progress"] }
MSRV: Rust 1.89+ (edition 2024).
Quick Start
Classical Machine Learning
use *;
use array;
Neural Networks
use *;
use Array;
Graph Models
A sequential model passes each layer's output to the next layer.
GraphBuilder connects layer calls as nodes in a graph.
A graph can have multiple inputs, multiple outputs, shared layers, and residual connections.
The merge layers join branches: Add, Subtract, Multiply, Average, Maximum, Minimum, and Concatenate.
use *;
use Array;
Evaluating a Model
use *;
use array;
Modules
The public modules group the API by task:
machine_learning: estimators for classification, regression, clustering, decomposition, and anomaly detection.neural_network: layers, model builders, losses, optimizers, and checkpoints.utils: preprocessing, label conversion, scalers, and dataset splits.metrics: classification, regression, and clustering scores.math: distance functions, matrix operations, and reductions.error: shared error types and result aliases.random: thread-local seed controls.traits: common estimator contracts.tuning: runtime thresholds for serial and parallel work.prelude: grouped imports for public types and traits.
See the API reference.
Feature Flags
The crate uses feature flags for modular compilation:
| Feature | Description |
|---|---|
machine_learning |
Classical ML algorithms (enables math) |
neural_network |
Neural-network framework (enables math) |
utils |
Data preprocessing and dataset splitting (enables math) |
metrics |
Evaluation metrics (enables math) |
math |
Numerical primitives (distances, matrix products, parallel reductions) |
full |
All of the above modules |
default |
full |
show_progress |
Render training/iteration progress bars in the terminal |
Project Status
RustyML is under active development. Minor releases can change the API before 1.0.0.
Contributing
Contributions are welcome. To help build the Rust ML library, you can:
- Open issues for bugs or feature requests
- Submit pull requests for improvements
- Share feedback on the API design
- Improve the documentation and examples
Please also review the Code of Conduct.
Author
SomeB1oody (stanyin64@gmail.com)
License
The MIT License covers this project. See the LICENSE file for details.