1.2. Installation and Feature Flags
First you need a Rust toolchain installed locally — Rust 1.89 or newer, with cargo available. Check with:
rustc --version
cargo --version
The output should look something like:
rustc 1.96.0 (ac68faa20 2026-05-25)
cargo 1.96.0 (30a34c682 2026-05-25)
Note that RustyML turns on every feature by default. If you want to trim it down and enable only part of it, you can configure that by hand in Cargo.toml; that is covered further down, so there is nothing to worry about yet.
1.2.1. Adding RustyML to your project
If you have not created a project yet, make one with cargo:
cargo new my_project # replace my_project with whatever name you want
A successful run prints something like:
$ cargo new my_project
Creating binary (application) `my_project` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
RustyML is easy to find on crates.io.
Open the project’s Cargo.toml and add this under [dependencies]:
[dependencies]
rustyml = "0.14"
ndarray = "0.17"
- The first line means “use version 0.14 of the
rustymlcrate with its default features” (that is, with everything enabled), so all of RustyML is available to you. - The second line means “use version 0.17 of the
ndarraycrate”. You will almost always needndarrayas a direct dependency as well, because it is the crate RustyML depends on to carry your data.
Sometimes you do not need all of RustyML’s features, and you can pick a combination by adjusting the features field on that first dependency. A few common shapes:
# Omitting `features` means the default feature set (everything)
rustyml = "0.14"
# Just the neural-network framework (requires turning the default off)
rustyml = { version = "0.14", default-features = false, features = ["neural_network"] }
# Everything: machine_learning, neural_network, utils, metrics, math (equivalent to default)
rustyml = { version = "0.14", features = ["full"] }
# Everything, plus terminal progress bars during training
rustyml = { version = "0.14", features = ["full", "show_progress"] }
7.4 Minimal Builds and Modular Integration goes into trimming features in depth.
1.2.2. The feature matrix
Eight features control the build. default and full are bundles.
| Feature | Module | Contents |
|---|---|---|
machine_learning | rustyml::machine_learning | Regression, classification, clustering, dimensionality reduction, anomaly detection |
neural_network | rustyml::neural_network | Keras-style neural-network architecture: Sequential, layers, optimizers, losses |
utils | rustyml::utils | Standardization, normalization, label encoding, train/test splitting |
metrics | rustyml::metrics | Evaluation metrics for regression, classification, and clustering |
math | rustyml::math | Numeric computation, gemmkit-backed matrix products, deterministic parallel reductions |
default | machine_learning + neural_network + utils + metrics + math | Every module, enabled when you name no features at all |
full | machine_learning + neural_network + utils + metrics + math | Every module |
show_progress | (no module of its own) | Terminal progress bars; see 1.2.6 |
Some things the table cannot show:
machine_learning,neural_network,utils, andmetricsall enablemathautomatically. You never need to addmathby hand alongside another module — only if the numeric module is all you want (see 6. Math Utilities).rustyml::error(the unifiedErrortype, see 1.6 Error Handling) andrustyml::random(global-seed control, see 7.1 Reproducibility and Random Seeds) appear whenever any ofmachine_learning,neural_network, orutilsis on — but not in ametrics-only ormath-only build, since those two leaf modules neither returnRustymlResultnor consume randomness.rustyml::tuning(runtime parallelism gates, see 7.3 Performance Tuning and Parallelism) is present no matter which feature you enable.- The
rustyml::preludemodule is always compiled, so you can always import through it; see 1.5 The Prelude and Imports.
1.2.3. Which third-party crates each feature pulls in
The table below shows which third-party libraries each RustyML feature needs. You do not need any of this to use the crate; it is here so you can see the dependency picture.
| Feature | Third-party crates it activates |
|---|---|
math | ndarray, ahash, rayon, gemmkit-ndarray |
machine_learning | ndarray, rayon, ndarray-rand, ahash, serde, postcard, thiserror, gemmkit-ndarray |
neural_network | ndarray, rayon, ndarray-rand, indicatif, serde, postcard, thiserror, gemmkit-ndarray |
utils | ndarray, rayon, ndarray-rand, ahash, serde, postcard, thiserror, gemmkit-ndarray |
metrics | ndarray, ahash, rayon, gemmkit-ndarray |
show_progress | indicatif |
| Crate | Version | What it does |
|---|---|---|
| ndarray | 0.17 + rayon feature + serde feature | Provides the array types and their methods |
| rayon | 1.12 | Parallel computation |
| ndarray-rand | 0.16 | Seeds random initialization |
| ahash | 0.8 + serde feature | Fast hash maps behind label encoding |
| serde | 1.0 + derive feature | Serializes and deserializes model weights |
| postcard | 1.1 + use-std feature | Stores and reads back model weights |
| thiserror | 2.0 | Derives the Error enum |
| indicatif | 0.18 | Draws progress bars |
| gemmkit | 0.1 (rayon parallelism on by default) | Pure-Rust high-performance GEMM engine; decides serial vs. parallel and the worker count itself. Reached through the adapter, not named as a direct dependency |
| gemmkit-ndarray | 0.1 + epilogue feature | Zero-copy ndarray adapter (a transpose or strided slice needs no copy); epilogue fuses bias/activation into the product |
The matrix-multiply backend lives in gemmkit rather than in RustyML. It exposes GEMMKIT_* environment variables for machine-specific tuning rather than general scheduling; see 7.3 Performance Tuning and Parallelism.
serde, postcard, and thiserror are the heavy dependencies. Dropping them (by staying on metrics and/or math) shrinks build time and the dependency count — for example:
rustyml = { version = "0.14", default-features = false, features = ["metrics"] }
1.2.4. A minimal end-to-end check
With the dependency written into Cargo.toml, put this in src/main.rs:
use rustyml::prelude::machine_learning::*;
use ndarray::array;
fn main() {
// 3 samples, 2 features
let x = array![[1.0, 2.0], [2.0, 3.0], [3.0, 4.0]];
let y = array![6.0, 9.0, 12.0];
// new(fit_intercept) -> Self; the default solver is exact OLS.
let mut model = LinearRegression::new(true);
model.fit(&x, &y).unwrap(); // train the model
// predict with the trained model
let predictions = model.predict(&x).unwrap();
println!("predicted {} values", predictions.len());
}
Run cargo run; the expected output is:
predicted 3 values
1.2.5. Pairing with ndarray
RustyML uses the array types ndarray provides, both on the way in and on the way out. The classical machine-learning module takes an Array2<f64> feature matrix and an Array1<f64> target vector; the neural network uses Tensor, an alias for ArrayD<f32> (note that ML and utilities are f64 while the network is f32). RustyML 0.14 builds against ndarray 0.17, so make sure the ndarray version in your Cargo.toml is 0.17.
RustyML does not re-export ndarray’s constructors, so building the arrays you feed in (array!, Array2::from_shape_vec, Array::ones, and friends) means calling into the ndarray crate. That is why it has to be a dependency in your Cargo.toml. 1.3 Working with ndarray covers the array-building patterns the estimators expect.
1.2.6. Using show_progress for training progress bars
show_progress adds no types and unlocks no module. With it enabled, the terminal shows a progress bar with elapsed time, position, and the current loss, and prints “Training completed” when it finishes; the mini-batch loop (fit_with_batches) shows the average loss over the batches of the epoch it is part-way through. That bar is not how you get the loss out — fit and fit_with_batches return a History carrying one loss per epoch whether or not the feature is on. What it buys you is watching the number move while a long run is still going, instead of reading it once the call returns.
Add "show_progress" to rustyml’s features in Cargo.toml:
rustyml = { version = "0.14", features = ["full", "show_progress"] }
Run cargo run again and you will see the bar (there is so little data in this example that you may not catch it moving):
[00:00:00] ######################################## 1000/1000 | Cost: 0.001324 | Max iterations | Iterations: 1000
predicted 3 values
It is best turned on only for interactive use.
1.2.7. MSRV
RustyML’s minimum supported Rust version is 1.89. On an older toolchain the resolver refuses the crate. rustup update stable updates the toolchain.
Beyond that there is nothing to configure — which is exactly RustyML’s advantage.