What is out-of-bag (OOB) error in a Random Forest?

Last updated 5 November 2026

OOB error is a built-in validation estimate. Each training sample is predicted using only the trees that did not see it in their bootstrap sample, and the error of those predictions is measured against the true labels.

  • Where OOB samples come from:

    • Each tree trains on a bootstrap sample (drawn with replacement) containing about 63.2% unique rows.

    • The remaining ~36.8% (≈ 1/e) are that tree's out-of-bag rows.

  • How it is computed:

    1. For each sample, collect predictions only from the trees where it was OOB.

    2. Aggregate them: majority vote or averaged probabilities for classification, the mean for regression.

    3. Compare the aggregated predictions with the true values across all samples to get the misclassification rate, MSE, or another metric.

  • Why it is useful:

    • It is close to an unbiased estimate of generalization error, comparable to cross-validation, without a holdout set or refitting.

    • In scikit-learn, set oob_score=True (requires bootstrap=True), then read oob_score_ and oob_decision_function_ or oob_prediction_.

  • Caveats:

    • It is slightly pessimistic, because each sample is scored by only about a third of the trees.

    • It is invalid when rows are not independent (time series, grouped or duplicated data), and it ignores leakage from preprocessing done on the full dataset.

  • https://en.wikipedia.org/wiki/Out-of-bag_error
  • https://pub.towardsai.net/top-20-random-forest-interview-questions-answers-17e8738abfbc
  • https://medium.com/@abhishekjainindore24/out-of-bag-evaluation-in-random-forest-6a4e57ebc485
All Random Forests interview questions