← Pinterest Interview Insights
The coding part was fine once I remembered to use random.choices for sampling with replacement.
Start by outlining the bagging algorithm: for each of B rounds, create a bootstrap sample by sampling with replacement, fit a DecisionTree on that sample, and aggregate predictions via majority vote (classification) or averaging (regression). Then discuss the bias-variance trade-off, emphasizing that bagging reduces variance without increasing bias, and explain how B and out-of-bag estimation affect performance.
Pro tip: Mention that out-of-bag samples provide a nearly unbiased estimate of generalization error without a separate validation set, and that increasing B reduces variance but yields diminishing returns, so B is often chosen based on computational budget.
Explain that bagging trains multiple decision trees on bootstrap samples and aggregates their predictions. Use a list to store models and a list of lists for out-of-bag indices.
For each round, generate a bootstrap sample by randomly selecting n indices with replacement from the training set. Track which indices are not selected as out-of-bag for that round.
Fit a DecisionTree on each bootstrap sample. For prediction, collect outputs from all trees and combine via majority vote (classification) or mean (regression).
Explain that bagging reduces variance by averaging decorrelated trees, without substantially increasing bias. The bias remains similar to a single tree, but variance decreases as B increases.
Describe how increasing B reduces variance but with diminishing returns, and how out-of-bag samples provide a validation-like error estimate without extra data.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.