{"id":50644265,"url":"https://github.com/SomeB1oody/RustyML","last_synced_at":"2026-07-01T01:00:43.869Z","repository":{"id":284094388,"uuid":"953343446","full_name":"SomeB1oody/RustyML","owner":"SomeB1oody","description":"A high-performance machine learning library in pure Rust, offering statistical utilities, ML algorithms and neural networks.","archived":false,"fork":false,"pushed_at":"2026-06-24T16:54:31.000Z","size":6124,"stargazers_count":341,"open_issues_count":1,"forks_count":65,"subscribers_count":32,"default_branch":"master","last_synced_at":"2026-06-24T18:22:10.444Z","etag":null,"topics":["ai","machine-learning","machine-learning-algorithms","rust-crate"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SomeB1oody.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-23T06:07:12.000Z","updated_at":"2026-06-24T16:54:37.000Z","dependencies_parsed_at":"2025-03-31T20:26:24.351Z","dependency_job_id":"fe7d6e5b-ed58-418d-9395-a8bcad4e663c","html_url":"https://github.com/SomeB1oody/RustyML","commit_stats":null,"previous_names":["someb1oody/rust_ai","someb1oody/rustyml"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/SomeB1oody/RustyML","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SomeB1oody%2FRustyML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SomeB1oody%2FRustyML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SomeB1oody%2FRustyML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SomeB1oody%2FRustyML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SomeB1oody","download_url":"https://codeload.github.com/SomeB1oody/RustyML/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SomeB1oody%2FRustyML/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34988714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","machine-learning","machine-learning-algorithms","rust-crate"],"created_at":"2026-06-07T11:00:30.249Z","updated_at":"2026-07-01T01:00:43.863Z","avatar_url":"https://github.com/SomeB1oody.png","language":"Rust","funding_links":[],"categories":["Machine Learning"],"sub_categories":[],"readme":"[简体中文](https://github.com/SomeB1oody/RustyML/blob/master/README.zh-CN.md) | [English](https://github.com/SomeB1oody/RustyML/blob/master/README.md)\n\n# RustyML\n\nA high-performance machine learning and deep learning library written in **pure Rust**.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.rust-lang.org/\"\u003e\u003cimg alt=\"rustc\" src=\"https://img.shields.io/badge/rustc-1.89%2B-brown\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://doc.rust-lang.org/edition-guide/\"\u003e\u003cimg alt=\"edition\" src=\"https://img.shields.io/badge/edition-2024-orange\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/SomeB1oody/RustyML/blob/master/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/badge/License-MIT-green\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://crates.io/crates/rustyml\"\u003e\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/rustyml.svg\"\u003e\u003c/a\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/SomeB1oody/RustyML/actions/workflows/fmt.yml\"\u003e\u003cimg alt=\"fmt\" src=\"https://img.shields.io/github/actions/workflow/status/SomeB1oody/RustyML/fmt.yml?branch=master\u0026label=fmt\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/SomeB1oody/RustyML/actions/workflows/clippy.yml\"\u003e\u003cimg alt=\"clippy\" src=\"https://img.shields.io/github/actions/workflow/status/SomeB1oody/RustyML/clippy.yml?branch=master\u0026label=clippy\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/SomeB1oody/RustyML/actions/workflows/test.yml\"\u003e\u003cimg alt=\"test\" src=\"https://img.shields.io/github/actions/workflow/status/SomeB1oody/RustyML/test.yml?branch=master\u0026label=test\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/SomeB1oody/RustyML/actions/workflows/doc.yml\"\u003e\u003cimg alt=\"doc\" src=\"https://img.shields.io/github/actions/workflow/status/SomeB1oody/RustyML/doc.yml?branch=master\u0026label=doc\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Overview\n\nRustyML is a complete ecosystem for machine learning and deep learning, built end to end in\nRust with no C/C++ dependencies. It covers the full workflow — from data preprocessing and\nfeature engineering, through model training, to evaluation — while leaning on Rust's memory\nsafety, fearless concurrency, and zero-cost abstractions.\n\nEverything is organized into five feature-gated modules, so you compile only what you use:\n`machine_learning`, `neural_network`, `utils`, `metrics`, and `math`, plus a shared `prelude`.\n\n## Highlights\n\n- **Pure Rust, no FFI** — memory-safe and portable, with nothing to link against.\n- **Parallelized by default** — heavy kernels use [Rayon](https://github.com/rayon-rs/rayon) for multi-threaded computation.\n- **Broad algorithm coverage** — classical supervised/unsupervised learning, anomaly detection, and a full neural-network framework.\n- **Unified, structured error handling** — every fallible call returns `RustymlResult\u003cT\u003e`; errors are grouped into clear category variants instead of opaque strings.\n- **Reproducible by design** — a single `set_global_seed` call makes every randomized component deterministic.\n- **Model persistence** — save and load trained models and network weights as compact binary via [Serde](https://serde.rs/) and [postcard](https://docs.rs/postcard/).\n- **Rich evaluation metrics** — regression, classification (binary \u0026 multiclass), and clustering, mirroring scikit-learn conventions.\n- **Modular features** — pull in just `metrics`, just `math`, the `default` learning stack, or the `full` crate.\n\n## Installation\n\nAdd RustyML to your `Cargo.toml`:\n\n```toml\n[dependencies]\nrustyml = { version = \"*\", features = [\"full\"] }\nndarray = \"0.17\"\n```\n\nPick the feature set that fits your needs:\n\n```toml\n# Default: classical ML + neural networks\nrustyml = \"*\"\n\n# Just the neural-network framework\nrustyml = { version = \"*\", features = [\"neural_network\"] }\n\n# Everything (ml, nn, utils, metrics, math)\nrustyml = { version = \"*\", features = [\"full\"] }\n\n# Show training progress bars in the terminal\nrustyml = { version = \"*\", features = [\"full\", \"show_progress\"] }\n```\n\n\u003e **MSRV:** Rust 1.89+ (edition 2024).\n\n## Quick Start\n\n### Classical Machine Learning\n\n```rust\nuse rustyml::prelude::machine_learning::*;\nuse ndarray::array;\n\n// Train a regularization-free linear regression model\nlet mut model = LinearRegression::new(true, 0.01, 1000, 1e-6).unwrap();\n\nlet x = array![[1.0, 2.0], [2.0, 3.0], [3.0, 4.0]];\nlet y = array![6.0, 9.0, 12.0];\n\nmodel.fit(\u0026x, \u0026y).unwrap();\nlet predictions = model.predict(\u0026x).unwrap();\nprintln!(\"{:?}\", predictions);\n\n// Persist and reload the trained model\nmodel.save_to_path(\"linear_regression.bin\").unwrap();\nlet restored = LinearRegression::load_from_path(\"linear_regression.bin\").unwrap();\n```\n\n### Neural Networks\n\n```rust\nuse rustyml::neural_network::sequential::Sequential;\nuse rustyml::prelude::neural_network::*;\nuse ndarray::Array;\n\n// 32 samples, 784 input features, 10 output classes\nlet x = Array::ones((32, 784)).into_dyn();\nlet y = Array::ones((32, 10)).into_dyn();\n\nlet mut model = Sequential::new();\nmodel\n    .add(Dense::new(784, 128, Activation::ReLU).unwrap())\n    .add(Dense::new(128, 64, Activation::ReLU).unwrap())\n    .add(Dense::new(64, 10, Activation::Softmax).unwrap())\n    .compile(\n        Adam::new(0.001, 0.9, 0.999, 1e-8, 0.0).unwrap(),\n        CategoricalCrossEntropy::new(false),\n    );\n\nmodel.summary(); // print the architecture\nmodel.fit(\u0026x, \u0026y, 10).unwrap();\n\nlet predictions = model.predict(\u0026x).unwrap();\nprintln!(\"Predictions shape: {:?}\", predictions.shape());\n\n// Save the trained weights, then load them into a fresh model\nmodel.save_to_path(\"model.bin\").unwrap();\n```\n\n### Evaluating a Model\n\n```rust\nuse rustyml::metrics::*;\nuse ndarray::array;\n\n// Arguments are always (y_true, y_pred), matching scikit-learn\nlet y_true = array![1.0, 0.0, 0.0, 1.0, 1.0];\nlet y_pred = array![1.0, 0.0, 1.0, 1.0, 0.0];\n\nlet cm = ConfusionMatrix::new(\u0026y_true.view(), \u0026y_pred.view());\nprintln!(\"Accuracy: {:.3}\", cm.accuracy());\nprintln!(\"F1 score: {:.3}\", cm.f1_score());\n```\n\n## Modules\n\n### `machine_learning`\n\nClassical supervised and unsupervised algorithms, all with parallel-processing optimization,\ninput validation, and binary persistence.\n\n| Category | Algorithms |\n|----------|------------|\n| **Regression** | Linear Regression (optional L1/L2 regularization) |\n| **Classification** | Logistic Regression, K-Nearest Neighbors, Decision Tree (ID3 / C4.5 / CART), SVC (kernel SMO), Linear SVC, Linear Discriminant Analysis |\n| **Clustering** | KMeans (K-means++ init), DBSCAN, MeanShift |\n| **Dimensionality Reduction** | PCA (multiple SVD solvers), KernelPCA (RBF / Linear / Poly / Sigmoid / Cosine kernels), t-SNE |\n| **Anomaly Detection** | Isolation Forest |\n\nShared config types live in [`types`](https://docs.rs/rustyml/latest/rustyml/types/index.html):\n`DistanceCalculationMetric` (Euclidean / Manhattan / Minkowski), `RegularizationType` (L1 / L2),\nand `KernelType` (Linear / Poly / RBF / Sigmoid / Cosine). Predictive models implement the\nunified `Fit` and `Predict` traits; the dimensionality-reduction transformers\n([`decomposition`](https://docs.rs/rustyml/latest/rustyml/machine_learning/decomposition/index.html)\nand [`manifold`](https://docs.rs/rustyml/latest/rustyml/machine_learning/manifold/index.html))\nimplement `Transform` / `FitTransform`.\n\n### `neural_network`\n\nA complete framework for building, training, and serializing feed-forward and\nconvolutional/recurrent networks via a Keras-style `Sequential` API.\n\n- **Core layers** — `Dense`, `Flatten`\n- **Activations** — `ReLU`, `Sigmoid`, `Tanh`, `Softmax`, `Linear` (as the `Activation` enum or standalone layers)\n- **Convolution** — `Conv1D`, `Conv2D`, `Conv3D`, `DepthwiseConv2D`, `SeparableConv2D`\n- **Pooling** — Max / Average pooling for 1D, 2D, 3D, plus their global variants\n- **Recurrent** — `SimpleRNN`, `LSTM`, `GRU`\n- **Regularization** — `Dropout`, `SpatialDropout{1,2,3}D`, `GaussianNoise`, `GaussianDropout`\n- **Normalization** — `BatchNormalization`, `LayerNormalization`, `InstanceNormalization`, `GroupNormalization`\n- **Optimizers** — `SGD` (with momentum), `Adam`, `AdamW`, `RMSprop`, `AdaGrad`\n- **Losses** — `MeanSquaredError`, `MeanAbsoluteError`, `BinaryCrossEntropy`, `CategoricalCrossEntropy`, `SparseCategoricalCrossEntropy`\n\nTraining supports full-batch (`fit`) and mini-batch (`fit_with_batches`) loops, weight\ninspection (`get_weights`), and binary serialization (`save_to_path` / `load_from_path`).\n\n### `utils`\n\nData preprocessing and dataset splitting. (Dimensionality reduction — `PCA`, `KernelPCA`,\n`TSNE` — now lives in `machine_learning` under `decomposition` and `manifold`.)\n\n- **Scaling** — `standardize` (z-score), `normalize` (configurable axis \u0026 order)\n- **Label encoding** — `to_categorical`, `to_categorical_with_mapping`, `to_sparse_categorical`\n- **Splitting** — `train_test_split` and `train_test_split_stratified`, with a configurable ratio\n\n### `metrics`\n\nA broad evaluation suite. All functions take `(y_true, y_pred)` and panic on precondition\nviolations (mismatched lengths, empty input) rather than returning `Result`, keeping this leaf\nmodule dependency-light.\n\n- **Regression** — MSE, RMSE, MAE, median absolute error, MAPE, R², explained variance\n- **Classification** — accuracy, `ConfusionMatrix` \u0026 `MulticlassConfusionMatrix`, ROC AUC, log loss, Cohen's κ, top-k accuracy, average precision, ROC \u0026 precision-recall curves\n- **Clustering** — Adjusted Rand Index, Normalized / Adjusted Mutual Information, homogeneity / completeness / V-measure, Fowlkes–Mallows, silhouette, Davies–Bouldin, Calinski–Harabasz\n\n### `math`\n\nPure, stateless numerical primitives shared across the crate: impurity measures (`entropy`,\n`gini`), distances (`squared_euclidean_distance_row`, `manhattan_distance_row`,\n`minkowski_distance_row`), statistics (`variance`, `standard_deviation`, `sum_of_square_total`,\n`sum_of_squared_errors`), and activation/loss helpers (`sigmoid`, `logistic_loss`,\n`hinge_loss`).\n\n### `prelude`\n\nOne-stop imports, split by domain so you only pull in what you need:\n\n```rust\nuse rustyml::prelude::machine_learning::*; // ML models (incl. PCA/KernelPCA/t-SNE), traits, config enums\nuse rustyml::prelude::neural_network::*;   // layers, optimizers, losses\nuse rustyml::prelude::utils::*;            // scaling, label encoding, splitting\nuse rustyml::prelude::metrics::*;          // evaluation metrics\nuse rustyml::prelude::math::*;             // math primitives\n```\n\n## Feature Flags\n\nThe crate uses feature flags for modular compilation:\n\n| Feature | Description |\n|---------|-------------|\n| `machine_learning` | Classical ML algorithms (enables `math`) |\n| `neural_network` | Neural-network framework |\n| `utils` | Data preprocessing and dataset splitting (enables `math`) |\n| `metrics` | Evaluation metrics (enables `math`) |\n| `math` | Mathematical and statistical primitives |\n| `default` | `machine_learning` + `neural_network` |\n| `full` | All of the above modules |\n| `show_progress` | Render training/iteration progress bars in the terminal |\n\n## Reproducibility\n\nEvery randomized component (weight initialization, K-means++, Isolation Forest, t-SNE, dropout,\n…) resolves its `random_state: Option\u003cu64\u003e` against a shared entry point. Set one global seed and\nthe whole crate becomes deterministic:\n\n```rust\nuse rustyml::set_global_seed;\n\nset_global_seed(42);\n// ... train models; results are now reproducible across runs ...\n```\n\nA per-call `random_state` takes precedence over the global seed, which in turn takes precedence\nover system entropy. See the [`random`](https://docs.rs/rustyml/latest/rustyml/random/index.html)\nmodule for the full resolution rules.\n\n## Error Handling\n\nOutside the `metrics` and `math` leaf modules, every fallible operation returns\n`RustymlResult\u003cT\u003e` (an alias for `Result\u003cT, rustyml::error::Error\u003e`). The `Error` type is structured into\ncategory variants and groups domain-specific failures into nested `NnError`, `TreeError`, and\n`IoError` sub-enums, so you can match on what actually went wrong instead of parsing strings.\n\n## Project Status\n\nRustyML is under active development. The API is stabilizing, but breaking changes may still land\nin minor releases before `1.0.0`.\n\n## Contributing\n\nContributions are welcome! If you'd like to help build a robust ML ecosystem in Rust, you can:\n\n1. Open issues for bugs or feature requests\n2. Submit pull requests for improvements\n3. Share feedback on the API design\n4. Improve the documentation and examples\n\nPlease also review the [Code of Conduct](https://github.com/SomeB1oody/RustyML/blob/master/CODE_OF_CONDUCT.md).\n\n## Author\n\nSomeB1oody — [stanyin64@gmail.com](mailto:stanyin64@gmail.com)\n\n## License\n\nLicensed under the [MIT License](https://github.com/SomeB1oody/RustyML/blob/master/LICENSE). See the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSomeB1oody%2FRustyML","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSomeB1oody%2FRustyML","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSomeB1oody%2FRustyML/lists"}