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

PeerJ Comput Sci. 2024 Nov 18:10:e2445. doi: 10.7717/peerj-cs.2445. eCollection 2024.

Abstract

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: Absent levels; Categorical predictors; Label encoding; Out-of-bag error; Random forest; Variable importance.

Grants and funding

This research is supported by a Massey University School of Fundamental Sciences scholarship. The New Zealand Food Safety Science & Research Centre (NZFSSRC) has paid for the APC of this article. The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript.