Ensemble Methods — ML Technical Interview Questions & Answers
Bagging, boosting and stacking multiple models.
Ensemble Methods
- Simple meaning: Ensemble = combine several models so the team beats one student. Bagging (random forest): parallel, vote. Boosting (XGBoost): sequential, fix errors. Stacking: a second model learns from the others’ guesses.
- Picture: Three weak trees. Alone 60%. Together 80% if their mistakes differ.
- Diversity matters. Ten copies of the same logistic model don’t help.
- Trap: ensembling until the laptop melts without a validation check. Trap: mixing bagging and boosting definitions.
Technical Interview Tip: Bagging = vote in parallel. Boosting = fix in a queue.
Code Examples for Ensemble Methods
Ensemble Methods — working example
# PCA-style intuition: project 2D → 1D by a direction vector
points = [(1.0, 1.0), (2.0, 2.0), (3.0, 2.8)]
# unit direction along y = x
ux, uy = 0.7071, 0.7071
proj = [x * ux + y * uy for x, y in points]
print([round(v, 3) for v in proj])
# Tiny ensemble: average two model votes
votes = [1, 0, 1]
v2 = [1, 1, 1]
ens = [1 if a + b >= 2 else 0 for a, b in zip(v1, v2)]
print(ens)Ensemble Methods — dim reduction compresses features; ensembles combine models; deep nets/RL/NLP are specialized families — practice the core math idea first.
How to Explain Ensemble Methods to an Interviewer
Bagging example?
Random forest
Boosting example?
XGBoost Gradient boosting