smartcore

Library Featured

Machine Learning in Rust.

Checked · Sources

Downloads
39,473
Dependents
33
Stars
976
Forks
111
Contributors
40
Commits
608
Latest release
0.7.0 ·

About

From the project README ·

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 datasets feature no longer enables std_rand (#416).

  • The generators make_blobs, make_circles and make_moons no longer take their seed from the OS RNG.
  • Without std_rand they use a fixed seed and return the same output on every call.
  • With std_rand they 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:

ToolChart URLWhat it plotsDirectionAlert
criterion (wall-clock)https://smartcorelib.github.io/smartcore-benches/dev/cargo bench wall-clock time per bench (ns/iter) over timelower = better200% — 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-independentlower = better120% — 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.

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.

smartcore beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
smartcore This page Featured

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
rustlearn Listed Dormant

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

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
rust-xgboost Listed Dormant

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 App Listed Dormant

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 days
  • dormancy: last activity 2026-11-07, 2 days ago, E = 365: active
  • featured: 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
Adoption11 active dependents, 6 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents11crates.io database dumpYes
New dependents (365 days)6crates.io database dumpYes
Peak active dependents14crates.io database dumpYes
Active dependents as a share of the peak0.95crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 2 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-11-07GitHub repositoryYes
Latest release2026-10-26crates.io database dumpYes
First release2021-01-03crates.io database dumpYes
Latest version0.7.0crates.io database dumpYes
Days the oldest outside issue waits for a reply69GitHub repositoryYes
Maintainer replies over 365 days88GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution29 releases, 39,473 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases29crates.io database dumpYes
Downloads over 30 days39473crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository976 stars, 111 forks, 40 contributors, 608 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars976GitHub repositoryYes — one part of the repository route
GitHub forks111GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account40GitHub contributorsYes — one part of the repository route
Commits on the default branch608GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0crates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly33crates.io database dumpNo

Corrections and review history

Report a correction

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.