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 decision;
54pub mod descriptor;
55pub mod diagnostics;
56pub mod drift;
57pub mod error;
58pub mod evaluate;
59pub mod feature_hasher;
60pub mod loss;
61pub mod metrics;
62pub mod models;
63pub mod optim;
64pub mod persistence;
65pub mod pipeline;
66pub mod preprocessing;
67#[cfg(feature = "bandit")]
68pub mod replay;
69pub mod sparse;
70pub mod stats;
71pub mod traits;
72pub mod weighted;
73
74pub use error::RillError;
75pub use evaluate::{BinaryClassificationSample, RegressionSample};
76pub use persistence::{MAX_SNAPSHOT_JSON_BYTES, SNAPSHOT_FORMAT_VERSION, Snapshot, ValidateState};
77pub use traits::{
78    Metric, OnlineBinaryClassifier, OnlineRegressor, OnlineStatistic, SparseClassifier,
79    SparseRegressor, Transformer,
80};
81pub use weighted::{WeightedOnlineBinaryClassifier, WeightedOnlineRegressor, WeightedStatistic};
82
83/// Version of the `rill-ml` crate as compiled into this library.
84/// Additive constant; reflects the Stable crate version of this build.
85pub const RILL_VERSION: &str = env!("CARGO_PKG_VERSION");