Ensemble learning
Understand why combining models can improve prediction and where it fails.
Compare a single model, bagging and boosting using the same evaluation splits.
Interview questions
Choose a question to reveal its answer.
01EasyCoreHow does bagging reduce variance?
Answer
How does bagging reduce variance?
Fits multiple estimators on resampled data and aggregates their predictions.
Train trees on bootstrap samples to reduce prediction variance.
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, random_state=42)
# Fit and compare on the same splits as a single tree.Randomized trees are combined by averaging class probabilities in scikit-learn.
02EasyCoreHow do you construct a bootstrap sample?
Answer
How do you construct a bootstrap sample?
Sample drawn with replacement from an original dataset.
Construct training subsets with repeated observations.
03EasyCoreWhat is an out-of-bag score?
Answer
What is an out-of-bag score?
Evaluates an example using ensemble members whose bootstrap samples excluded it.
Approximate random forest performance without a separate validation fit.
04MediumHigh priorityHow does boosting differ from bagging?
Answer
How does boosting differ from bagging?
Builds a sequence of learners to improve a combined objective.
Add trees that improve the current model's errors.
05MediumHigh priorityHow does AdaBoost update sample emphasis?
Answer
How does AdaBoost update sample emphasis?
Sequentially emphasizes examples that prior weak classifiers misclassified under its weighting scheme.
Train weak classifiers with adjusted sample weights.
06MediumHow does gradient boosting fit successive learners?
Answer
How does gradient boosting fit successive learners?
Adds learners that approximate negative loss gradients.
Fit successive trees to residual-like targets.
07MediumWhat is shrinkage in boosting?
Answer
What is shrinkage in boosting?
Scales each new learner's contribution using a learning rate.
Reduce the impact of individual boosting stages.
08MediumHow do you avoid leakage when training a stacking model?
Answer
How do you avoid leakage when training a stacking model?
Trains a meta-model on predictions of base estimators, typically out-of-fold.
Combine tree and linear model predictions using a second-level model.
09HardHow does soft voting combine classifiers?
Answer
How does soft voting combine classifiers?
Aggregates class predictions or probabilities across classifiers.
Average class probabilities from multiple models.
10HardWhy does model diversity matter in ensembles?
Answer
Why does model diversity matter in ensembles?
Differences in component errors that can make aggregation beneficial.
Combine models whose failures are not strongly correlated.
Priority and difficulty are editorial study recommendations.
Technical reference: Documentation / paper ↗
Try a few practice questions
Explore the questions before creating a free account.
1. Which method trains independent estimators on bootstrap samples and aggregates them?
2. Why train a stacking meta-model on out-of-fold predictions?
3. What does shrinkage do in gradient boosting?
Regularization and generalization
Continue to the next set of interview questions.