smartcore
Library Featured
Machine Learning in Rust.
- Downloads
- 39,473
- Dependents
- 33
- Stars
- 976
- Forks
- 111
- Contributors
- 40
- Commits
- 608
- Latest release
- 0.7.0 ·
About
User guide | API | Notebooks
Machine Learning in Rust
To start getting familiar with the smartcore API, there is now available a Jupyter Notebook environment repository. Please see instructions there, contributions welcome see CONTRIBUTING.
smartcore is a fast, ergonomic machine learning library for Rust, covering classical supervised and unsupervised methods with a modular linear algebra abstraction and optional ndarray support. It aims to provide production-friendly APIs, strong typing, and good defaults while remaining flexible for research and experimentation.
Highlights
- Broad algorithm coverage: linear models, tree-based methods, ensembles, SVMs, neighbors, clustering, decomposition, and preprocessing.
- Strong linear algebra traits with optional ndarray integration for users who prefer array-first workflows.
- WASM-first defaults with attention to portability; features such as serde and datasets are opt-in.
- Practical utilities for model selection, evaluation, readers (CSV), dataset generators, and built-in sample datasets.
Install
Add to Cargo.toml:
[dependencies]
smartcore = "^0.7"
For the latest changes from the main branch:
Read the full README
[dependencies]
smartcore = { git = "https://github.com/smartcorelib/smartcore", branch = "main" }
Optional features (examples):
- datasets
- serde
- ndarray-bindings (deprecated in favor of ndarray-only support per recent changes)
Check Cargo.toml for available features and compatibility notes.
Breaking changes in 0.7.0
[!WARNING] The
datasetsfeature no longer enablesstd_rand(#416).
- The generators
make_blobs,make_circlesandmake_moonsno longer take their seed from the OS RNG.- Without
std_randthey use a fixed seed and return the same output on every call.- With
std_randthey take their seed from OS entropy, as before.To keep the 0.6 behaviour, enable both features:
[dependencies] smartcore = { version = "^0.7", features = ["datasets", "std_rand"] }
Quick start
Here is a minimal example fitting a KNN classifier from native Rust vectors using DenseMatrix:
use smartcore::linalg::basic::matrix::DenseMatrix;
use smartcore::neighbors::knn_classifier::KNNClassifier;
// Turn vector slices into a matrix
let x = DenseMatrix::from_2d_array(&[
&[1., 2.],
&[3., 4.],
&[5., 6.],
&[7., 8.],
&[9., 10.],
]).unwrap();
// Class labels
let y = vec![2, 2, 2, 3, 3];
// Train classifier
let knn = KNNClassifier::fit(&x, &y, Default::default()).unwrap();
// Predict
let yhat = knn.predict(&x).unwrap();
This example mirrors the “First Example” section of the crate docs and demonstrates smartcore’s ergonomic API surface.
Algorithms
smartcore organizes algorithms into clear modules with consistent traits:
- Clustering: K-Means, DBSCAN, agglomerative (including single-linkage), with K-Means++ initialization and utilities.
- Matrix decomposition: SVD, EVD, Cholesky, LU, QR, plus related linear algebra helpers.
- Linear models: OLS, Ridge, Lasso, ElasticNet, Logistic Regression.
- Ensemble and tree-based: Random Forest (classifier and regressor), Extra Trees, shared reusable components across trees and forests.
- SVM: SVC/SVR with kernel enum support and multiclass extensions.
- Neighbors: KNN classification and regression with distance metrics and fast selection helpers.
- Naive Bayes: Gaussian, Bernoulli, Categorical, Multinomial.
- Preprocessing: encoders, split utilities, and common transforms.
- Model selection and metrics: K-fold, search parameters, and evaluation utilities.
Recent refactors emphasize reusable components in trees/forests and expanded multiclass SVM capabilities. XGBoost-style regression and single-linkage clustering have been added. See CHANGELOG for API changes and migration notes.
Optional lazy normalization
The optional lazy-normalization feature lets Lasso and Elastic Net borrow the
design matrix during normalization. Elastic Net also applies its identity-block
augmentation without storing the augmented design. Enable it with features = ["lazy-normalization"], then select it with
LassoParameters::default().with_lazy_normalization(true) or
ElasticNetParameters::default().with_lazy_normalization(true). The default
remains eager, even when the feature is enabled. The normalize option still
controls whether columns are centered and scaled. Parameter searches use the
fixed lazy_normalization setting. It works with DenseMatrix and
ndarray-bindings.
Lazy normalization reduces memory use by computing normalized values when the solver needs them. This adds repeated arithmetic and can increase fit time for both estimators, including Elastic Net on large inputs. The solver still stores a dense Gram matrix with one row and column per feature.
Enabling the feature adds a public lazy_normalization field to both estimators'
parameter and search parameter structs. Code that constructs these structs
without ..Default::default() must add the field. Missing fields default to
false during deserialization.
Data access and readers
- CSV readers: Read matrices from CSV with configurable delimiter and header rows, with helpful error messages and testing utilities (including non-IO reader abstractions).
- Dataset generators: make_blobs, make_circles, make_moons for quick experiments. Since 0.7.0 they use a fixed seed unless you also enable
std_rand(see the breaking changes note above). - Built-in datasets (feature-gated): digits, diabetes, breast cancer, boston, with serialization utilities to persist or refresh .xy bundles.
WebAssembly and portability
smartcore adopts a WASM/WASI-first posture in defaults to ease browser and embedded deployments. Some file-system operations are restricted in wasm targets; tests and IO utilities are structured to avoid unsupported calls where possible. Enable features like serde selectively to minimize footprint. Consult module-level docs and CHANGELOG for target-specific caveats.
Notebooks
A curated set of Jupyter notebooks is available via the companion repository to explore smartcore interactively. To run locally, use EVCXR to enable Rust notebooks. This is the recommended path to quickly experiment with the smartcore API.
Roadmap and recent changes
- Trait-system refactor, fewer structs and more object-safe traits, large codebase reorganization.
- Move to Rust 2024 edition (MSRV 1.85) and cleanup of duplicate code paths.
- Seeds and deterministic controls across algorithms using RNG plumbing.
- Search parameter API for hyperparameter exploration in K-Means and SVM families.
- Tree and forest components refactored for reuse; Extra Trees added.
- SVM multiclass support; SVR kernel enum and related improvements.
- XGBoost-style regression introduced; single-linkage clustering implemented.
- Classification metrics hardened: multiclass macro F1 now averages per-class F-measures (matching sklearn), and Precision/Recall/F1 share a single per-class confusion-counts helper so the per-class bookkeeping lives in one place.
See CHANGELOG.md for precise details, deprecations, and breaking changes. Some features like nalgebra-bindings have been dropped in favor of ndarray-only paths. Default features are tuned for WASM/WASI builds; enable serde/datasets as needed.
Live trend charts
benchmark-action/github-action-benchmark renders an interactive chart page per tool on the gh-pages branch, published via GitHub Pages:
| Tool | Chart URL | What it plots | Direction | Alert |
|---|---|---|---|---|
| criterion (wall-clock) | https://smartcorelib.github.io/smartcore-benches/dev/ | cargo bench wall-clock time per bench (ns/iter) over time | lower = better | 200% — advisory, posts a comment, does not fail CI |
| iai-callgrind (instruction count) | https://smartcorelib.github.io/smartcore-benches/iai-dev/ | instructions retired (Ir) per bench — deterministic, machine-independent | lower = better | 120% — fails the iai job + status check |
Open the URLs above in a browser. Each page shows a searchable line chart (data.js is the raw history) with one series per benchmark name (e.g. matmul/1024, iai_matmul::matmul::bench_matmul_256). Hover for the value, range, and commit that produced each point. The iai page is the one to watch for regressions: instruction counts are deterministic on
Contributing
Contributions are welcome:
- Open an issue describing the change and link it in the PR.
- Keep PRs in sync with the main branch and ensure tests pass on stable Rust (MSRV 1.85, edition 2024).
- Provide or update tests; run clippy and apply formatting. Coverage and linting are part of the workflow.
- Use the provided PR and issue templates to describe behavior changes, new features, and expectations.
If adding IO, prefer abstractions that make non-IO testing straightforward (see readers/iotesting). For datasets, keep serialization helpers in tests gated appropriately to avoid unintended file writes in wasm targets.
License
smartcore is open source under a permissive license; see Cargo.toml and LICENSE for details. The crate metadata identifies “smartcore Developers” as authors; community contributions are credited via Git history and releases.
Acknowledgments
smartcore’s design incorporates well-known ML patterns while staying idiomatic to Rust. Thanks to all contributors who have helped expand algorithms, improve docs, modernize traits, and harden the codebase for production.
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- None found
- No native code found
- Python bindings
- No Python binding crate found
- License
- Apache-2.0
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Machine Learning in Rust. |
39,473 downloads over 30 days | 33 | 976 | 0.7.0 | GPU support unknown | No native code found | Apache-2.0 |
|
linfa Featured
A Machine Learning framework for Rust |
177,963 downloads over 30 days | 60 | 4,770 | 0.8.1 | GPU support unknown | Binds native code: lapack-sys (feature intel-mkl-static) | Apache-2.0 OR MIT |
|
A machine learning package for Rust. |
578 downloads over 30 days | 2 | 647 | 0.5.0 | GPU support unknown | Binds native code: libsvm | Apache-2.0 |
|
rust-automl Listed
Automated machine learning for classification and regression |
170 downloads over 30 days | 1 | 39 | 0.3.1 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
Machine learning using XGBoost |
112 downloads over 30 days | 1 | 122 | 0.1.4 | GPU support unknown | Binds native code: xgboost, xgboost-sys. Build uses a native toolchain: bindgen | MIT |
|
treeboost Listed
Gradient-boosted decision trees for tabular data: trains a baseline model in one call, with full control over boosting modes and configs, and Scalar, AVX-512, SVE2, WGPU and CUDA backends. Python bindings |
18 downloads over 30 days | 0 | 9 | 0.1.2 | CUDA, WebGPU | No native code found | Apache-2.0 |
|
Fwumious Wabbit, fast on-line machine learning toolkit written in Rust |
0 binary downloads per release | Not applicable | 141 | Not measured | Not measured | Not measured |
Why FeaturedIt passes every Featured gate.
What it meets
- It has 11 active dependents and 6 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
- Active dependents are at 95% of their peak. Featured needs at least 50%.
- Docs are present. The release commit or a manifest ties the crate to the repository.
- No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
- The last activity is on 7 Nov 2026, 2 days ago. The rules expect an update within 365 days. Dormancy rule
Exact rules: Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.7.0 base 140, doubled for 11 active users, raised to the 365-day floor: E = 365 daysdormancy: last activity 2026-11-07, 2 days ago, E = 365: activefeatured: featured: active_users 11, new_adopters 6, former_glory 0.95
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption11 active dependents, 6 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 11 | crates.io database dump | Yes | |
| New dependents (365 days) | 6 | crates.io database dump | Yes | |
| Peak active dependents | 14 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 0.95 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 2 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-11-07 | GitHub repository | Yes | |
| Latest release | 2026-10-26 | crates.io database dump | Yes | |
| First release | 2021-01-03 | crates.io database dump | Yes | |
| Latest version | 0.7.0 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 69 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 88 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution29 releases, 39,473 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 29 | crates.io database dump | Yes | |
| Downloads over 30 days | 39473 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository976 stars, 111 forks, 40 contributors, 608 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 976 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 111 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 40 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 608 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | No native code found | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 33 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.