A lightweight, from-scratch machine learning toolkit in Rust.
-
Linear Algebra:
Vector
struct for basic operations (dot
,scale
,add
,sub
,zeros
). -
Models:
- Linear Regression (batch gradient descent, feature normalization)
- Logistic Regression (sigmoid, cross-entropy, classification)
-
Preprocessing:
- one_hot_encoding: convert categorical columns to binary matrix
- impute: mean imputation for missing numeric values
- scale: standard (zero-mean/unit-variance) and min-max scaling
- split: train/test and k-fold splitting of indices
-
CSV Loading: parse CSV files into mixed-type map or numeric-only map
-
Demos:
linear_regression_demo
logistic_regression_demo
# Clone the repository
git clone [email protected]:moh-dev-stack/ml_in_rust.git
cd ml_in_rust
# Build the library and demos
cargo build --release
Add to your Cargo.toml
:
[dependencies]
ml_in_rust = { git = "https://github.com/moh-dev-stack/ml_in_rust" }
Then in your code:
use ml_in_rust::algebra::vector::Vector;
use ml_in_rust::models::linear_regression::gradient_descent;
// ...
# Linear regression demo
cargo run --bin linear_regression_demo
# Logistic regression demo
cargo run --bin logistic_regression_demo
src/
├─ algebra/ # Vector and linear algebra primitives
├─ models/ # Machine learning algorithms
│ ├─ linear_regression.rs
│ └─ logistic_regression.rs
├─ preprocessing/ # Feature-engineering utilities
│ ├─ one_hot_encoding.rs
│ ├─ impute.rs
│ ├─ scale.rs
│ └─ split.rs
├─ utils/ # CSV loading and parsing
└─ bin/ # Example binaries
├─ linear_regression_demo.rs
└─ logistic_regression_demo.rs
tests/ # Integration tests for each module
Run the full test suite with:
cargo test
This project is open source under the MIT License. See LICENSE
for details.