rustlearn
A machine learning package for Rust.
For full usage details, see the API documentation.
Introduction
This crate contains reasonably effective implementations of a number of common machine learning algorithms.
At the moment, rustlearn
uses its own basic dense and sparse array types, but I will be happy
to use something more robust once a clear winner in that space emerges.
Features
Matrix primitives
Models
- logistic regression using stochastic gradient descent,
- support vector machines using the
libsvm
library, - decision trees using the CART algorithm,
- random forests using CART decision trees, and
- factorization machines.
All the models support fitting and prediction on both dense and sparse data, and the implementations
should be roughly competitive with Python sklearn
implementations, both in accuracy and performance.
Cross-validation
Metrics
Parallelization
A number of models support both parallel model fitting and prediction.
Model serialization
Model serialization is supported via rustc_serialize
. This will probably change to serde
once compiler plugins land in stable.
Using rustlearn
Usage should be straightforward.
- import the prelude for alll the linear algebra primitives and common traits:
use *;
- import individual models and utilities from submodules:
use *;
use Hyperparameters;
// more imports
Examples
Logistic regression
use *;
use iris;
use CrossValidation;
use Hyperparameters;
use accuracy_score;
let = load_data;
let num_splits = 10;
let num_epochs = 5;
let mut accuracy = 0.0;
for in new
accuracy /= num_splits as f32;
Random forest
use *;
use Hyperparameters;
use iris;
use decision_tree;
let = load_data;
let mut tree_params = new;
tree_params.min_samples_split
.max_features;
let mut model = new
.one_vs_rest;
model.fit.unwrap;
// Optionally serialize and deserialize the model
// let encoded = bincode::rustc_serialize::encode(&model,
// bincode::SizeLimit::Infinite).unwrap();
// let decoded: OneVsRestWrapper<RandomForest> = bincode::rustc_serialize::decode(&encoded).unwrap();
let prediction = model.predict.unwrap;
Contributing
Pull requests are welcome.
To run basic tests, run cargo test
.
Running cargo test --features "all_tests" --release
runs all tests, including generated and slow tests.
Running cargo bench --features bench
(only on the nightly branch) runs benchmarks.