#[non_exhaustive]pub struct StackingClassifier { /* private fields */ }Expand description
Stacking (stacked generalization) classifier.
Trains base estimators via k-fold cross-validation, collects out-of-fold predictions as meta-features, then trains a final meta-learner on those meta-features. At predict time, base estimator predictions are fed to the meta-learner.
§Examples
ⓘ
use scry_learn::ensemble::StackingClassifier;
use scry_learn::tree::DecisionTreeClassifier;
use scry_learn::linear::LogisticRegression;
let sc = StackingClassifier::new(
vec![
Box::new(DecisionTreeClassifier::new().max_depth(3)),
Box::new(DecisionTreeClassifier::new().max_depth(7)),
],
Box::new(LogisticRegression::new()),
).cv(5);Implementations§
Source§impl StackingClassifier
impl StackingClassifier
Sourcepub fn new(
estimators: Vec<Box<dyn EnsembleClassifier>>,
final_estimator: Box<dyn EnsembleClassifier>,
) -> Self
pub fn new( estimators: Vec<Box<dyn EnsembleClassifier>>, final_estimator: Box<dyn EnsembleClassifier>, ) -> Self
Create a new stacking classifier.
estimators are the base learners; final_estimator is the meta-learner.
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Fit the stacking classifier.
- Split data into
cvfolds. - For each fold, train base learners on training folds and collect out-of-fold predictions.
- Assemble meta-features from out-of-fold predictions.
- Train the final estimator on meta-features.
- Re-train all base learners on the full dataset for prediction.
Trait Implementations§
Source§impl Clone for StackingClassifier
impl Clone for StackingClassifier
Source§fn clone(&self) -> StackingClassifier
fn clone(&self) -> StackingClassifier
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for StackingClassifier
impl !RefUnwindSafe for StackingClassifier
impl Send for StackingClassifier
impl Sync for StackingClassifier
impl Unpin for StackingClassifier
impl UnsafeUnpin for StackingClassifier
impl !UnwindSafe for StackingClassifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more