ensemble_methods
Concept Overview
Section titled “Concept Overview”The diagnostics behind the bagging-versus-boosting choice rather than another ensemble implementation. bias_variance_noise decomposes the error; average_pairwise_prediction_correlation measures how correlated your base learners actually are; bagging_ensemble_variance turns that rho into the variance a bagged ensemble can reach, sigma^2(rho + (1-rho)/N). The consequence AFML Chapter 6 draws is the useful one: as N grows the ensemble variance floors at sigma^2·rho, so with highly correlated learners more estimators buy nothing at all.
When to Use
Section titled “When to Use”Use it before scaling an ensemble. If measured rho is 0.9, going from 20 to 200 estimators is wasted compute, and recommend_bagging_vs_boosting will say so from the numbers rather than from folklore. Reach for bagging when the base learner is unstable (variance-dominated) and boosting when it is weak (bias-dominated). Under heavy label overlap use sequential_bootstrap_sample_indices instead of the IID bootstrap, or the bags will be near-duplicates of each other.
Mathematical Foundations
Section titled “Mathematical Foundations”Error Decomposition
Section titled “Error Decomposition”
Bagging Variance Under Average Correlation
Section titled “Bagging Variance Under Average Correlation”
Majority Vote and Mean Probability
Section titled “Majority Vote and Mean Probability”
Usage Examples
Section titled “Usage Examples”Assess Ensemble Variance and Recommendation
Section titled “Assess Ensemble Variance and Recommendation”use openquant::ensemble_methods::{ average_pairwise_prediction_correlation, bagging_ensemble_variance, recommend_bagging_vs_boosting,};
let preds = vec![ vec![0.51, 0.49, 0.52, 0.50], vec![0.50, 0.48, 0.53, 0.49], vec![0.52, 0.50, 0.51, 0.50],];
let rho = average_pairwise_prediction_correlation(&preds)?;let bag_var = bagging_ensemble_variance(1.0, rho, 20)?;let decision = recommend_bagging_vs_boosting(0.54, rho, 0.75, 1.0, 20)?;
println!("rho={rho:.3}, var={bag_var:.3}, rec={:?}", decision.recommended);Aggregate Bagged Classifier Outputs
Section titled “Aggregate Bagged Classifier Outputs”use openquant::ensemble_methods::{ aggregate_classification_vote, aggregate_classification_probability_mean,};
let vote = aggregate_classification_vote(&[ vec![1, 0, 1], vec![1, 1, 0], vec![0, 1, 1],])?;
let (mean_prob, labels) = aggregate_classification_probability_mean(&[ vec![0.9, 0.2, 0.6], vec![0.8, 0.3, 0.5], vec![0.7, 0.4, 0.4],], 0.5)?;
assert_eq!(vote, vec![1, 1, 1]);assert_eq!(labels, vec![1, 0, 1]);assert_eq!(mean_prob.len(), 3);API Reference
Section titled “API Reference”Python API
Section titled “Python API”ensemble.bias_variance_noiseensemble.bootstrap_sample_indicesensemble.sequential_bootstrap_sample_indicesensemble.aggregate_regression_meanensemble.aggregate_classification_voteensemble.aggregate_classification_probability_meanensemble.average_pairwise_prediction_correlationensemble.bagging_ensemble_varianceensemble.recommend_bagging_vs_boosting
Rust API
Section titled “Rust API”bias_variance_noisebootstrap_sample_indicessequential_bootstrap_sample_indicesaggregate_classification_voteaggregate_classification_probability_meanaverage_pairwise_prediction_correlationbagging_ensemble_variancerecommend_bagging_vs_boosting
Risk Notes and Caveats
Section titled “Risk Notes and Caveats”- If base learners are highly correlated, bagging variance reduction is minimal even with many estimators.
- Sequential-bootstrap-style sampling is preferable under heavy label overlap and non-IID observations.
- Boosting is usually preferable for weak learners (bias reduction); bagging is usually preferable for unstable learners (variance reduction).