| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
Add to Cargo.toml:
[dependencies]
smartcore = "^0.6"For the latest development branch:
[dependencies]
smartcore = { git = "https://github.com/smartcorelib/smartcore", branch = "development" }Optional features (examples):
Check Cargo.toml for available features and compatibility notes.
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.
smartcore organizes algorithms into clear modules with consistent traits:
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.
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.
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.
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.
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
Contributions are welcome:
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.
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.
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.
| Back | FazBrowse Home | New Git URL |