Skip to main content

rill_ml/
lib.rs

1//! # RillML
2//!
3//! Lightweight, serializable online machine learning for Rust applications
4//! and streaming data.
5//!
6//! RillML provides incremental learning primitives that can be embedded
7//! directly in native Rust applications: online statistics, preprocessors,
8//! linear/logistic regression, evaluation metrics, pipelines, progressive
9//! evaluation, drift detection, online decision-making (bandits), and optional
10//! serde-based state persistence.
11//!
12//! ## Quick start
13//!
14//! ```rust
15//! use rill_ml::{
16//!     metrics::Mae,
17//!     models::{LinearRegression, LinearRegressionConfig},
18//!     optim::{Optimizer, SgdConfig},
19//!     pipeline::RegressionPipeline,
20//!     preprocessing::StandardScaler,
21//!     Metric, OnlineRegressor,
22//! };
23//!
24//! let feature_count = 2;
25//! let scaler = StandardScaler::new(feature_count).unwrap();
26//! let mut sgd = SgdConfig::default();
27//! sgd.learning_rate = 0.05;
28//! sgd.l2 = 0.0;
29//! let optimizer = Optimizer::sgd(feature_count, sgd).unwrap();
30//! let mut lr_config = LinearRegressionConfig::default();
31//! lr_config.optimizer = optimizer;
32//! let regression = LinearRegression::new(feature_count, lr_config).unwrap();
33//! let mut model = RegressionPipeline::new(scaler, regression).unwrap();
34//! let mut mae = Mae::default();
35//!
36//! let samples = [
37//!     ([0.1, 0.2], 0.5),
38//!     ([0.3, 0.8], 1.4),
39//!     ([0.6, 0.4], 1.1),
40//! ];
41//! for (features, target) in samples {
42//!     let prediction = model.predict(&features).unwrap();
43//!     mae.update(target, prediction).unwrap();
44//!     model.learn(&features, target).unwrap();
45//! }
46//! ```
47
48#![cfg_attr(docsrs, feature(doc_cfg))]
49
50#[cfg(feature = "bandit")]
51#[cfg_attr(docsrs, doc(cfg(feature = "bandit")))]
52pub mod bandit;
53pub mod diagnostics;
54pub mod drift;
55pub mod error;
56pub mod evaluate;
57pub mod feature_hasher;
58pub mod loss;
59pub mod metrics;
60pub mod models;
61pub mod optim;
62pub mod persistence;
63pub mod pipeline;
64pub mod preprocessing;
65pub mod sparse;
66pub mod stats;
67pub mod traits;
68
69pub use error::RillError;
70pub use evaluate::{BinaryClassificationSample, RegressionSample};
71pub use persistence::{MAX_SNAPSHOT_JSON_BYTES, SNAPSHOT_FORMAT_VERSION, Snapshot, ValidateState};
72pub use traits::{
73    Metric, OnlineBinaryClassifier, OnlineRegressor, OnlineStatistic, SparseClassifier,
74    SparseRegressor, Transformer,
75};