PeerJ Computer Science (Nov 2024)

Out of (the) bag—encoding categorical predictors impacts out-of-bag samples

  • Helen L. Smith,
  • Patrick J. Biggs,
  • Nigel P. French,
  • Adam N. H. Smith,
  • Jonathan C. Marshall

DOI
https://doi.org/10.7717/peerj-cs.2445
Journal volume & issue
Vol. 10
p. e2445

Abstract

Read online Read online

Performance of random forest classification models is often assessed and interpreted using out-of-bag (OOB) samples. Observations which are OOB when a tree is trained may serve as a test set for that tree and predictions from the OOB observations used to calculate OOB error and variable importance measures (VIM). OOB errors are popular because they are fast to compute and, for large samples, are a good estimate of the true prediction error. In this study, we investigate how target-based vs. target-agnostic encoding of categorical predictor variables for random forest can bias performance measures based on OOB samples. We show that, when categorical variables are encoded using a target-based encoding method, and when the encoding takes place prior to bagging, the OOB sample can underestimate the true misclassification rate, and overestimate variable importance. We recommend using a separate test data set when evaluating variable importance and/or predictive performance of tree based methods that utilise a target-based encoding method.

Keywords