pub struct AdaBoost<M, L> {
pub models: Vec<M>,
pub model_weights: Vec<f64>,
pub classes: Vec<L>,
}Expand description
A fitted AdaBoost ensemble classifier.
§Structure
AdaBoost (Adaptive Boosting) is an ensemble learning method that combines multiple weak learners into a strong classifier. Unlike bagging methods (like Random Forest), AdaBoost trains learners sequentially, where each new learner focuses more on examples that previous learners misclassified.
Each fitted model M has an associated weight (alpha) that represents its contribution to the
final prediction. Models that perform better on their training data receive higher weights.
§Algorithm Overview
Given a DatasetBase denoted as D with n samples:
- Initialize sample weights uniformly:
w_i = 1/nfor all samples - For each iteration
tfrom 1 to T (number of estimators): a. Train base learner on weighted dataset b. Calculate weighted error rate c. Compute model weight (alpha) based on error d. Update sample weights: increase weights for misclassified samples e. Normalize sample weights
§Prediction Algorithm
The final prediction is computed using weighted majority voting:
- Each model’s prediction is weighted by its alpha value
- The class with the highest weighted vote is selected
§Example
use linfa::prelude::{Fit, Predict};
use linfa_ensemble::AdaBoostParams;
use linfa_trees::DecisionTree;
use ndarray_rand::rand::SeedableRng;
use rand::rngs::SmallRng;
// Load Iris dataset
let mut rng = SmallRng::seed_from_u64(42);
let (train, test) = linfa_datasets::iris()
.shuffle(&mut rng)
.split_with_ratio(0.8);
// Train AdaBoost with decision tree stumps
let adaboost_model = AdaBoostParams::new(DecisionTree::params().max_depth(Some(1)))
.n_estimators(50)
.learning_rate(1.0)
.fit(&train)
.unwrap();
// Make predictions on the test set
let predictions = adaboost_model.predict(&test);§References
- Freund, Y., & Schapire, R. E. (1997). A decision-theoretic generalization of on-line learning and an application to boosting. Journal of Computer and System Sciences, 55(1), 119-139.
- Scikit-Learn AdaBoost Documentation
- An Introduction to Statistical Learning, Chapter 8
Fields§
§models: Vec<M>The fitted base learner models
model_weights: Vec<f64>The weight (alpha) for each model in the ensemble
classes: Vec<L>The unique class labels seen during training
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<M, L> Freeze for AdaBoost<M, L>
impl<M, L> RefUnwindSafe for AdaBoost<M, L>where
M: RefUnwindSafe,
L: RefUnwindSafe,
impl<M, L> Send for AdaBoost<M, L>
impl<M, L> Sync for AdaBoost<M, L>
impl<M, L> Unpin for AdaBoost<M, L>
impl<M, L> UnsafeUnpin for AdaBoost<M, L>
impl<M, L> UnwindSafe for AdaBoost<M, L>where
M: UnwindSafe,
L: UnwindSafe,
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