Skip to main content

StackedEnsemble

Struct StackedEnsemble 

Source
pub struct StackedEnsemble { /* private fields */ }
Available on crate feature 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

Source

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
Source

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 models
  • meta_learner – combiner model
  • passthrough – if true, original features are appended to meta-features
Source

pub fn n_base_learners(&self) -> usize

Number of base learners in the ensemble.

Source

pub fn passthrough(&self) -> bool

Whether original features are passed through to the meta-learner.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StreamingLearner for StackedEnsemble

Source§

fn train_one(&mut self, features: &[f64], target: f64, weight: f64)

Train on a single weighted observation using temporal holdout.

  1. Collect base predictions before training (temporal holdout).
  2. Build meta-features and train the meta-learner on (meta_features, target, weight).
  3. Train each base learner on (features, target, weight).
Source§

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

Total number of samples trained on since creation or last reset.

Source§

fn reset(&mut self)

Reset all base learners, the meta-learner, and the sample counter.

Source§

fn train(&mut self, features: &[f64], target: f64)

Train on a single observation with unit weight. Read more
Source§

fn predict_batch(&self, feature_matrix: &[&[f64]]) -> Vec<f64>

Predict for each row in a feature matrix. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.