solow_preprocessing/lib.rs
1//! # solow-preprocessing
2//!
3//! Feature preprocessing for the Solow statistical stack — scalers, encoders,
4//! and feature construction.
5//!
6//! Every preprocessor exposes the classical `fit` / `transform` /
7//! `fit_transform` / `inverse_transform` shape from
8//! `preprocessing`, so a the reference practitioner can migrate a
9//! pipeline call-for-call. The types are also composable through
10//! [`solow-cv`](https://docs.rs/solow-cv)-style cross-validated scoring
11//! and through the higher-level `solow-fit` formula surface.
12//!
13//! ## Modules
14//!
15//! * [`scalers`] — [`StandardScaler`], [`MinMaxScaler`], [`RobustScaler`],
16//! [`MaxAbsScaler`], [`Normalizer`]. All support `partial_fit`-style
17//! incremental statistics update where applicable and derive
18//! `Serialize` / `Deserialize` under the opt-in `serde` feature.
19//! * [`encoders`] — [`LabelEncoder`] (1-D categorical `usize` ↔ label),
20//! [`OrdinalEncoder`] (per-column labels for a matrix), and
21//! [`OneHotEncoder`] with an optional `drop_first` for regression
22//! design-matrix compatibility.
23//! * [`polynomial`] — [`PolynomialFeatures`] with `degree`,
24//! `interaction_only`, and `include_bias` matching the reference
25//! semantics exactly.
26//! * [`discretize`] — [`KBinsDiscretizer`] with `Uniform`, `Quantile`,
27//! and `KMeans` binning strategies.
28//!
29//! Every preprocessor's `transform` is deterministic and side-effect-free;
30//! there is no hidden RNG. `KBinsDiscretizer::KMeans` is the only
31//! stochastic component and takes an explicit `seed`.
32//!
33//! ## Example — a full preprocessing chain
34//!
35//! ```
36//! use ndarray::array;
37//! use solow_preprocessing::{StandardScaler, PolynomialFeatures};
38//!
39//! let x = array![[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
40//!
41//! // Standardize.
42//! let scaler = StandardScaler::fit(x.view()).unwrap();
43//! let x_std = scaler.transform(x.view()).unwrap();
44//!
45//! // Expand to polynomial features up to degree 2 (no bias column).
46//! let poly = PolynomialFeatures::new(2).include_bias(false);
47//! let x_poly = poly.fit_transform(x_std.view()).unwrap();
48//!
49//! assert_eq!(x_poly.ncols(), 5); // x0, x1, x0², x0·x1, x1²
50//! ```
51
52#![forbid(unsafe_code)]
53#![warn(missing_docs)]
54
55pub mod binarizer;
56pub mod discretize;
57pub mod encoders;
58pub mod function_transformer;
59pub mod label_binarizer;
60pub mod polynomial;
61pub mod power;
62pub mod scalers;
63pub mod spline;
64pub mod target_encoder;
65
66pub use binarizer::Binarizer;
67pub use discretize::{BinStrategy, KBinsDiscretizer};
68pub use encoders::{LabelEncoder, OneHotEncoder, OrdinalEncoder};
69pub use function_transformer::FunctionTransformer;
70pub use label_binarizer::{LabelBinarizer, MultiLabelBinarizer};
71pub use polynomial::PolynomialFeatures;
72pub use power::{PowerMethod, PowerTransformer, QuantileOutput, QuantileTransformer};
73pub use scalers::{MaxAbsScaler, MinMaxScaler, NormKind, Normalizer, RobustScaler, StandardScaler};
74pub use spline::SplineTransformer;
75pub use target_encoder::TargetEncoder;
76
77/// Commonly-used imports.
78pub mod prelude {
79 pub use crate::binarizer::Binarizer;
80 pub use crate::discretize::{BinStrategy, KBinsDiscretizer};
81 pub use crate::encoders::{LabelEncoder, OneHotEncoder, OrdinalEncoder};
82 pub use crate::function_transformer::FunctionTransformer;
83 pub use crate::label_binarizer::{LabelBinarizer, MultiLabelBinarizer};
84 pub use crate::polynomial::PolynomialFeatures;
85 pub use crate::scalers::{
86 MaxAbsScaler, MinMaxScaler, NormKind, Normalizer, RobustScaler, StandardScaler,
87 };
88 pub use crate::spline::SplineTransformer;
89 pub use crate::target_encoder::TargetEncoder;
90}