Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 rustyml crate 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 ndarray crate”. You will almost always need ndarray as 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.

FeatureModuleContents
machine_learningrustyml::machine_learningRegression, classification, clustering, dimensionality reduction, anomaly detection
neural_networkrustyml::neural_networkKeras-style neural-network architecture: Sequential, layers, optimizers, losses
utilsrustyml::utilsStandardization, normalization, label encoding, train/test splitting
metricsrustyml::metricsEvaluation metrics for regression, classification, and clustering
mathrustyml::mathNumeric computation, gemmkit-backed matrix products, deterministic parallel reductions
defaultmachine_learning + neural_network + utils + metrics + mathEvery module, enabled when you name no features at all
fullmachine_learning + neural_network + utils + metrics + mathEvery 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, and metrics all enable math automatically. You never need to add math by hand alongside another module — only if the numeric module is all you want (see 6. Math Utilities).
  • rustyml::error (the unified Error type, see 1.6 Error Handling) and rustyml::random (global-seed control, see 7.1 Reproducibility and Random Seeds) appear whenever any of machine_learning, neural_network, or utils is on — but not in a metrics-only or math-only build, since those two leaf modules neither return RustymlResult nor consume randomness.
  • rustyml::tuning (runtime parallelism gates, see 7.3 Performance Tuning and Parallelism) is present no matter which feature you enable.
  • The rustyml::prelude module 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.

FeatureThird-party crates it activates
mathndarray, ahash, rayon, gemmkit-ndarray
machine_learningndarray, rayon, ndarray-rand, ahash, serde, postcard, thiserror, gemmkit-ndarray
neural_networkndarray, rayon, ndarray-rand, indicatif, serde, postcard, thiserror, gemmkit-ndarray
utilsndarray, rayon, ndarray-rand, ahash, serde, postcard, thiserror, gemmkit-ndarray
metricsndarray, ahash, rayon, gemmkit-ndarray
show_progressindicatif
CrateVersionWhat it does
ndarray0.17 + rayon feature + serde featureProvides the array types and their methods
rayon1.12Parallel computation
ndarray-rand0.16Seeds random initialization
ahash0.8 + serde featureFast hash maps behind label encoding
serde1.0 + derive featureSerializes and deserializes model weights
postcard1.1 + use-std featureStores and reads back model weights
thiserror2.0Derives the Error enum
indicatif0.18Draws progress bars
gemmkit0.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-ndarray0.1 + epilogue featureZero-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.