Skip to main content

millwright/
lib.rs

1//! # Millwright
2//!
3//! A unified ML framework for Rust — *ten crates, one lifecycle.*
4//!
5//! Millwright assembles proven Rust crates into one composable ML lifecycle —
6//! ingest and profile data, build and tune pipelines, evaluate and explain
7//! models, export to ONNX, and serve with drift monitoring — behind one data
8//! model, one trait contract, and feature-gated backends.
9//!
10//! - [`Frame`](frame::Frame) / [`Dataset`](frame::Dataset) — the numeric
11//!   boundary type the public API speaks. `Table` (feature `eda`) is the typed,
12//!   polars-backed front that lowers into it.
13//! - the **core contract** — object-safe [`Transformer`](traits::Transformer),
14//!   [`Estimator`](traits::Estimator), [`Predictor`](traits::Predictor), and
15//!   [`ProbaPredictor`](traits::ProbaPredictor) — plus specialized
16//!   [`Clusterer`](traits::Clusterer), [`Forecaster`](traits::Forecaster),
17//!   [`PartialFit`](traits::PartialFit), and [`Balancer`](traits::Balancer) for
18//!   the shapes that need them.
19//! - [`Pipeline`](pipeline::Pipeline) composition with `"step__param"`
20//!   addressing, over feature-gated backends (smartcore, linfa, …).
21//!
22//! Everything is object-safe, so a pipeline holds a heterogeneous chain of
23//! boxed steps and a boxed model. Each capability is a cargo feature; `default`
24//! is a lean core and `full` lights up the whole lifecycle. See the
25//! [guide](https://millwright-rs.dev/guide.html) for a tour.
26//!
27//! ```no_run
28//! use millwright::prelude::*;
29//!
30//! # fn main() -> millwright::Result<()> {
31//! let x = Frame::from_rows(
32//!     vec![vec![0.0, 0.0], vec![9.0, 9.0]],
33//!     vec!["a".into(), "b".into()],
34//! )?;
35//! let train = Dataset::new(x.clone(), vec![0.0, 1.0])?;
36//!
37//! let mut pipe = Pipeline::new()
38//!     .step("scale", StandardScaler::new())
39//!     .estimator("lr", LogisticRegression::new()); // a core, probability-capable model
40//!
41//! pipe.fit(&train)?;
42//! let preds = pipe.predict(&x)?;
43//! # let _ = preds;
44//! # Ok(())
45//! # }
46//! ```
47
48pub mod backends;
49pub mod error;
50pub mod evaluate;
51pub mod frame;
52pub mod logistic;
53pub mod pipeline;
54pub mod traits;
55pub mod transform;
56
57#[cfg(feature = "anomaly")]
58pub mod anomaly;
59#[cfg(feature = "automl")]
60pub mod automl;
61#[cfg(feature = "preprocessing")]
62pub mod balance;
63#[cfg(feature = "calibration")]
64pub mod calibration;
65#[cfg(feature = "diagnostics")]
66pub mod diagnostics;
67#[cfg(feature = "ensemble")]
68pub mod ensemble;
69#[cfg(feature = "explain")]
70pub mod explain;
71#[cfg(feature = "monitor")]
72pub mod monitor;
73#[cfg(feature = "onnx")]
74pub mod onnx;
75#[cfg(feature = "eda")]
76pub mod profile;
77#[cfg(feature = "registry")]
78pub mod registry;
79#[cfg(feature = "model-selection")]
80pub mod selection;
81#[cfg(feature = "serve")]
82pub mod serve;
83#[cfg(feature = "eda")]
84pub mod table;
85#[cfg(feature = "viz")]
86pub mod viz;
87
88#[cfg(any(feature = "model-selection", feature = "ensemble", feature = "explain"))]
89mod rng;
90
91#[cfg(feature = "python")]
92mod python;
93
94pub use error::{Error, Result};
95
96/// The one import that brings the whole framework into scope.
97pub mod prelude {
98    pub use crate::error::{Error, Result};
99    pub use crate::evaluate::{Evaluate, Report, Task};
100    pub use crate::frame::{Dataset, Dtype, Frame};
101    pub use crate::logistic::LogisticRegression;
102    pub use crate::pipeline::Pipeline;
103    pub use crate::traits::{
104        Balancer, Clusterer, Estimator, Forecaster, Model, ParamValue, PartialFit, Predictor,
105        ProbaPredictor, Transformer,
106    };
107    pub use crate::transform::{
108        ColumnTransformer, ImputeStrategy, MinMaxScaler, OneHotEncoder, PowerTransform,
109        SimpleImputer, StandardScaler, TargetEncoder, Winsorize,
110    };
111
112    #[cfg(feature = "smartcore-backend")]
113    pub use crate::backends::smartcore::{Knn, LinearRegression, NaiveBayes, RandomForest, Svc};
114
115    #[cfg(feature = "linfa-backend")]
116    pub use crate::backends::linfa::{Dbscan, GaussianMixture, KMeans, Pca};
117
118    #[cfg(feature = "timeseries")]
119    pub use crate::backends::chronos::AutoArima;
120
121    #[cfg(feature = "incremental")]
122    pub use crate::backends::incremental::IncrementalLinear;
123
124    #[cfg(feature = "preprocessing")]
125    pub use crate::balance::{RandomOverSampler, Smote};
126
127    #[cfg(feature = "model-selection")]
128    pub use crate::selection::{
129        CrossValidator, GridSearch, KFold, Metric, ParamGrid, RandomSearch, SearchResult,
130        StratifiedKFold,
131    };
132
133    #[cfg(feature = "hpo")]
134    pub use crate::selection::{BayesSearch, SearchSpace};
135
136    #[cfg(feature = "diagnostics")]
137    pub use crate::diagnostics::Diagnostics;
138
139    #[cfg(feature = "calibration")]
140    pub use crate::calibration::{
141        reliability_curve, CalibratedClassifier, CalibrationMethod, IsotonicRegression,
142        PlattScaling, ReliabilityBin,
143    };
144
145    #[cfg(feature = "anomaly")]
146    pub use crate::anomaly::{KnnScore, Mahalanobis, OutlierDetector};
147
148    #[cfg(feature = "eda")]
149    pub use crate::profile::{Alert, ColumnProfile, Profile, TargetKind, TargetProfile};
150    #[cfg(feature = "eda")]
151    pub use crate::table::{CategoryEncoding, ColKind, Table};
152
153    #[cfg(feature = "explain")]
154    pub use crate::explain::{permutation_importance, Explain, Explainer, Explanation};
155
156    #[cfg(feature = "viz")]
157    pub use crate::viz;
158
159    #[cfg(feature = "onnx")]
160    pub use crate::onnx::{ExportOnnx, InferenceModel};
161
162    #[cfg(feature = "registry")]
163    pub use crate::registry::{Metadata, Registry, Version};
164
165    #[cfg(feature = "monitor")]
166    pub use crate::monitor::{DriftMonitor, DriftStatus};
167
168    #[cfg(feature = "serve")]
169    pub use crate::serve::Server;
170
171    #[cfg(feature = "ensemble")]
172    pub use crate::ensemble::{Bagging, Boosting, Voting, VotingKind};
173
174    #[cfg(feature = "automl")]
175    pub use crate::automl::{AutoML, AutoMLResult, Budget};
176    #[cfg(all(feature = "ensemble", feature = "model-selection"))]
177    pub use crate::ensemble::Stacking;
178}