Skip to content

Repository files navigation

tests Crates.io docs.rs

rhai-ml

Machine learning for the Rhai scripting language, backed by SmartCore. Train linear, lasso, and logistic regression models directly in your scripts, with optional regularization settings.

Install

rhai-ml = "0.1.4"

Usage

use rhai_ml::eval;

let prediction = eval::<f64>(r#"
    let model = train([[0], [1], [2], [3]], [1, 3, 5, 7], "linear");
    predict([[4]], model)[0]
"#).unwrap();

assert!((prediction - 9.0).abs() < 0.000001);

To add the package to an existing Rhai engine:

use rhai::{packages::Package, Engine};
use rhai_ml::MLPackage;

let mut engine = Engine::new();
engine.register_global_module(MLPackage::new().as_shared_module());

Inputs must be nonempty rectangular arrays of finite numbers, with one target per training row. Logistic regression uses integer class labels. Invalid inputs return Rhai errors that scripts can handle with try/catch.

The optional metadata feature generates API documentation and tests the Rhai examples. Run cargo run --example quickstart to try all three algorithms.

See the API reference, input rules and errors, development checks, and changelog.

About

Machine learning for Rhai.

Topics

Resources

Contributing

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages