Expand description
§Ensemble Learning Algorithms
Ensemble methods combine the predictions of several base estimators built with a given learning algorithm in order to improve generalizability / robustness over a single estimator.
§Bootstrap Aggregation (aka Bagging)
A typical example of ensemble method is Bootstrapo AGgregation, which combines the predictions of
several decision trees (see linfa-trees) trained on different samples subset of the training dataset.
§Reference
§Example
This example shows how to train a bagging model using 100 decision trees, each trained on 70% of the training data (bootstrap sampling).
use linfa::prelude::{Fit, Predict};
use linfa_ensemble::EnsembleLearnerParams;
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 the model on the iris dataset
let bagging_model = EnsembleLearnerParams::new(DecisionTree::params())
.ensemble_size(100)
.bootstrap_proportion(0.7)
.fit(&train)
.unwrap();
// Make predictions on the test set
let predictions = bagging_model.predict(&test);