pub struct StackedEnsemble { /* private fields */ }alloc only.Expand description
Polymorphic model stacking meta-learner using Box<dyn StreamingLearner>.
Combines predictions from heterogeneous base learners through a trainable meta-learner. Uses temporal holdout to prevent information leakage: base predictions are collected before training the bases on each sample.
§Note on Clone
StackedEnsemble cannot implement Clone because Box<dyn StreamingLearner>
is not Clone. If you need to snapshot the ensemble, serialize it instead.
Implementations§
Source§impl StackedEnsemble
impl StackedEnsemble
Sourcepub fn new(
base_learners: Vec<Box<dyn StreamingLearner>>,
meta_learner: Box<dyn StreamingLearner>,
) -> Self
pub fn new( base_learners: Vec<Box<dyn StreamingLearner>>, meta_learner: Box<dyn StreamingLearner>, ) -> Self
Create a new stacked ensemble with passthrough disabled.
The meta-learner receives only base learner predictions as features.
§Arguments
base_learners– heterogeneous base models (at least one recommended)meta_learner– combiner model trained on base predictions
Sourcepub fn with_passthrough(
base_learners: Vec<Box<dyn StreamingLearner>>,
meta_learner: Box<dyn StreamingLearner>,
passthrough: bool,
) -> Self
pub fn with_passthrough( base_learners: Vec<Box<dyn StreamingLearner>>, meta_learner: Box<dyn StreamingLearner>, passthrough: bool, ) -> Self
Create a new stacked ensemble with configurable feature passthrough.
When passthrough is true, the meta-learner receives both base
predictions and the original feature vector, enabling it to learn
corrections that depend on raw inputs.
§Arguments
base_learners– heterogeneous base modelsmeta_learner– combiner modelpassthrough– iftrue, original features are appended to meta-features
Sourcepub fn n_base_learners(&self) -> usize
pub fn n_base_learners(&self) -> usize
Number of base learners in the ensemble.
Sourcepub fn passthrough(&self) -> bool
pub fn passthrough(&self) -> bool
Whether original features are passed through to the meta-learner.
Sourcepub fn base_predictions(&self, features: &[f64]) -> Vec<f64>
pub fn base_predictions(&self, features: &[f64]) -> Vec<f64>
Get predictions from each base learner for inspection.
Returns a vector with one prediction per base learner, in the same order they were provided at construction time.
Trait Implementations§
Source§impl Debug for StackedEnsemble
impl Debug for StackedEnsemble
Source§impl StreamingLearner for StackedEnsemble
impl StreamingLearner for StackedEnsemble
Source§fn train_one(&mut self, features: &[f64], target: f64, weight: f64)
fn train_one(&mut self, features: &[f64], target: f64, weight: f64)
Train on a single weighted observation using temporal holdout.
- Collect base predictions before training (temporal holdout).
- Build meta-features and train the meta-learner on
(meta_features, target, weight). - Train each base learner on
(features, target, weight).
Source§fn predict(&self, features: &[f64]) -> f64
fn predict(&self, features: &[f64]) -> f64
Predict by collecting base predictions and passing them through the meta-learner.
Source§fn n_samples_seen(&self) -> u64
fn n_samples_seen(&self) -> u64
Total number of samples trained on since creation or last reset.