| Crates.io | rustyml |
| lib.rs | rustyml |
| version | 0.10.0 |
| created_at | 2025-03-31 00:10:48.686865+00 |
| updated_at | 2026-01-19 18:33:36.374601+00 |
| description | A high-performance machine learning & deep learning library in pure Rust, offering statistical utilities, ML algorithms, and future support for transformer architectures. |
| homepage | |
| repository | https://github.com/SomeB1oody/RustyML |
| max_upload_size | |
| id | 1612891 |
| size | 2,305,539 |
A comprehensive machine learning and deep learning library written in pure Rust.
一个用纯Rust编写的全面机器学习和深度学习库。
RustyML aims to be a feature-rich machine learning and deep learning framework that leverages Rust's performance, memory safety, and concurrency features. While currently in early development stages, the project's long-term vision is to provide a complete ecosystem for machine learning, deep learning, and transformer-based models.
RustyML 旨在成为一个功能丰富的机器学习和深度学习框架,充分利用Rust的性能、内存安全性和并发特性。虽然目前处于早期开发阶段,但项目的长期愿景是提供一个完整的机器学习、深度学习和基于transformer架构的模型生态系统。
features = ["machine_learning"])Classical machine learning algorithms for supervised and unsupervised learning:
经典机器学习算法,用于监督和无监督学习:
Regression | 回归:
Classification | 分类:
Clustering | 聚类:
Anomaly Detection | 异常检测:
features = ["neural_network"])Complete neural network framework with flexible architecture design:
完整的神经网络框架,具有灵活的架构设计:
Layers | 层:
Optimizers | 优化器:
Loss Functions | 损失函数:
Models | 模型:
Activation layers | 激活层:
features = ["utility"])Data preprocessing and dimensionality reduction utilities:
数据预处理和降维工具:
Dimensionality Reduction | 降维:
Preprocessing | 预处理:
Kernel Functions | 核函数:
features = ["metric"])Comprehensive evaluation metrics for model performance assessment:
用于模型性能评估的全面评估指标:
Regression Metrics | 回归指标:
Classification Metrics | 分类指标:
Clustering Metrics | 聚类指标:
features = ["math"])Mathematical utilities and statistical functions:
数学工具和统计函数:
Distance Metrics | 距离度量:
Impurity Measures | 不纯度度量:
Statistical Functions | 统计函数:
Activation Functions | 激活函数:
features = ["dataset"])Access to standardized datasets for experimentation:
用于实验的标准化数据集:
Add the library to your Cargo.toml:
将库添加到您的Cargo.toml文件中:
[dependencies]
rustyml = {version = "0.9.1", features = ["machine_learning"]}
# or use `features = ["full"]` to enable all features
# Or use features = ["default"] to enable default modules (`machine_learning` and `neural_network`)
In your Rust code, write: 在你的Rust代码里写:
use rustyml::machine_learning::linear_regression::*; // or `use rustyml::prelude::*`
use ndarray::{Array1, Array2};
// Create a linear regression model
let mut model = LinearRegression::new(true, 0.01, 1000, 1e-6, None).unwrap();
// Prepare training data
let raw_x = vec![vec![1.0, 2.0], vec![2.0, 3.0], vec![3.0, 4.0]];
let raw_y = vec![6.0, 9.0, 12.0];
// Convert Vec to ndarray types
let x = Array2::from_shape_vec((3, 2), raw_x.into_iter().flatten().collect()).unwrap();
let y = Array1::from_vec(raw_y);
// Train the model
model.fit(&x.view(), &y.view()).unwrap();
// Make predictions
let new_data = Array2::from_shape_vec((1, 2), vec![4.0, 5.0]).unwrap();
let _predictions = model.predict(&new_data.view());
// Save the trained model to a file
model.save_to_path("linear_regression_model.json").unwrap();
// Load the model from the file
let loaded_model = LinearRegression::load_from_path("linear_regression_model.json").unwrap();
// Use the loaded model for predictions
let _loaded_predictions = loaded_model.predict(&new_data.view());
// Since Clone is implemented, the model can be easily cloned
let _model_copy = model.clone();
// Since Debug is implemented, detailed model information can be printed
println!("{:?}", model);
Add the library to your Cargo.toml:
将库添加到您的Cargo.toml文件中:
[dependencies]
rustyml = {version = "0.9.1", features = ["neural_network"]}
# or use `features = ["full"]` to enable all features
# Or use `features = ["default"]` to enable default modules (`machine_learning` and `neural_network`)
In your Rust code, write: 在你的Rust代码里写:
use rustyml::prelude::*;
use ndarray::Array;
// Create training data
let x = Array::ones((32, 784)).into_dyn(); // 32 samples, 784 features
let y = Array::ones((32, 10)).into_dyn(); // 32 samples, 10 classes
// Build a neural network
let mut model = Sequential::new();
model
.add(Dense::new(784, 128, ReLU::new()).unwrap())
.add(Dense::new(128, 64, ReLU::new()).unwrap())
.add(Dense::new(64, 10, Softmax::new()).unwrap())
.compile(Adam::new(0.001, 0.9, 0.999, 1e-8).unwrap(), CategoricalCrossEntropy::new());
// Display model structure
model.summary();
// Train the model
model.fit(&x, &y, 10).unwrap();
// Save model weights to file
model.save_to_path("model.json").unwrap();
// Create a new model with the same architecture
let mut new_model = Sequential::new();
new_model
.add(Dense::new(784, 128, ReLU::new()).unwrap())
.add(Dense::new(128, 64, ReLU::new()).unwrap())
.add(Dense::new(64, 10, Softmax::new()).unwrap());
// Load weights from file
new_model.load_from_path("model.json").unwrap();
// Compile before using (required for training, optional for prediction)
new_model.compile(Adam::new(0.001, 0.9, 0.999, 1e-8).unwrap(), CategoricalCrossEntropy::new());
// Make predictions with loaded model
let predictions = new_model.predict(&x);
println!("Predictions shape: {:?}", predictions.shape());
For Chinese mainland users, a mandarin video tutorial is provided on Bilibili, follow @SomeB1oody 对于中国大陆用户,B站有视频教程,关注@SomeB1oody
The crate uses feature flags for modular compilation:
该crate使用特性标志进行模块化编译:
| Feature | Description | 说明 |
|---|---|---|
machine_learning |
Classical ML algorithms (depends on math, utility) |
经典机器学习算法(依赖于math、utility) |
neural_network |
Neural network framework | 神经网络框架 |
utility |
Data preprocessing and dimensionality reduction | 数据预处理和降维 |
metric |
Evaluation metrics | 评估指标 |
math |
Mathematical utilities | 数学工具 |
dataset |
Standard datasets | 标准数据集 |
default |
Enables machine_learning and neural_network |
开启machine_learning和neural_network功能 |
full |
Enables all features | 启用所有功能 |
RustyML is in active development. While the API is stabilizing, breaking changes may occur in minor version updates until version 1.0.0. RustyML正在积极开发中。虽然API正在稳定,但在1.0.0版本之前,次要版本更新中可能会出现破坏性更改。
Contributions are welcome! If you're interested in helping build a robust machine learning ecosystem in Rust, please feel free to:
欢迎贡献!如果您有兴趣帮助构建Rust中的强大机器学习生态系统,请随时:
Licensed under the MIT License. See LICENSE file for details.
根据MIT许可证授权。有关详细信息,请参阅LICENSE文件。