Autoencoding Random Forests

Binh Duc Vu, Jan Kapar, Marvin N. Wright, David Watson

Abstract

Representation learning has traditionally been the domain of Deep Neural Networks (DNNs). However, for tabular datasets featuring mixed data types and complex non-linear relationships, tree-based models like Random Forests (RFs) often provide superior performance. This paper introduces Autoencoding Random Forests (RFAE), a principled framework that enables both encoding and decoding within the RF paradigm. By treating the forest as an adaptive kernel and utilizing spectral graph theory, RFAE constructs low-dimensional embeddings and provides a mathematically sound mechanism for data reconstruction. Our results show that RFAE frequently outperforms neural autoencoders on tabular benchmarks and effectively handles tasks such as denoising and batch correction in biological data.

1. Introduction

In machine learning, the ability to extract compact, informative features from raw data—representation learning—is a critical capability. While DNNs are the standard for images and text, they often struggle with tabular data found in spreadsheets and databases. In these contexts, Random Forests (RFs) remain the gold standard. Despite their predictive power, RFs have historically lacked a formal autoencoding framework. While similarity measures can be derived from forests, there has been no standard method to project data into a latent space and subsequently "invert" the forest to reconstruct the original input.

This paper addresses this gap by introducing Autoencoding Random Forests (RFAE). RFAE leverages the intrinsic geometry of the forest to perform dimensionality reduction and introduces novel strategies for decoding latent vectors back into the high-dimensional input space.

2. Methodology

The RFAE pipeline is divided into two primary stages: encoding the input into a latent representation and decoding that representation back to the original space.

2.1 Encoding via Spectral Geometry

The encoding process treats a trained Random Forest as an "adaptive kernel." A similarity matrix is constructed based on the frequency with which data points co-occur in the same leaf nodes across the ensemble. To transform this similarity matrix into a low-dimensional embedding ($Z$), the authors employ diffusion maps, a technique from spectral graph theory. By decomposing the similarity matrix into its eigenvectors, RFAE captures the underlying manifold of the data as defined by the forest's partitions.

2.2 Decoding Strategies

The most significant challenge in tree-based autoencoding is the "inversion" of the forest. Mapping a continuous latent vector back to a high-dimensional space is non-trivial for discrete tree structures. The authors propose three distinct strategies:

  1. Integer Linear Programming (ILP): An exact constrained optimization method that identifies the most likely leaf assignments. While mathematically rigorous, it is computationally intensive.
  2. Split Relabeling: This method involves "re-training" the internal logic of the forest to operate directly on the embedding space, allowing for a more direct mapping.
  3. k-Nearest Neighbors (k-NN): The most computationally efficient approach. It identifies the closest points in the latent space and reconstructs the input by averaging the "hyperrectangles" (leaf regions) defined by the forest.

2.3 Theoretical Contributions

Beyond the practical algorithms, the authors provide a formal proof that the RF kernel is asymptotically universal. This implies that with sufficient data and an adequate number of trees, the RF kernel can represent any continuous function, a property typically associated with kernels like the Gaussian Radial Basis Function (RBF).

3. Experimental Evaluation

The authors evaluated RFAE across three distinct domains: tabular benchmarks, image data, and biological sequences.

3.1 Tabular Benchmarks

Using 20 diverse datasets from the UCI and OpenML repositories (including Adult, Credit, and Mushroom), RFAE was compared against four state-of-the-art neural autoencoders, such as TVAE and optimized VAEs. RFAE achieved the best average rank (1.80), demonstrating its robustness across mixed continuous and categorical data types.

3.2 Image and Biological Data

On the MNIST dataset, RFAE embeddings demonstrated clear class separation that improved as tree depth increased, confirming that the latent space captures meaningful semantic information. In the realm of single-cell RNA sequencing (scRNA-seq), RFAE was applied to mouse brain studies for denoising and "batch effect" correction. RFAE successfully aligned data from different laboratories, outperforming standard techniques like PCA and t-SNE in preserving the biological manifold while mitigating technical noise.

4. Discussion and Conclusion

RFAE shifts the perception of Random Forests from a collection of "if-then" rules to a sophisticated geometric framework. By inverting the recursive partitions of the forest, the authors demonstrate that decoding is possible by identifying the intersection of leaf regions.

4.1 Limitations

The primary limitation of RFAE is the $O(n^2)$ complexity of the adjacency matrix used in the encoding step, which poses challenges for very large datasets. The authors suggest Nyström approximations as a potential solution. Additionally, the k-NN decoder requires careful selection of the hyperparameter $k$.

4.2 Future Work

Future research will explore extending the RFAE framework to Gradient Boosting Machines (GBMs) and investigating "model distillation," where these autoencoding insights are used to compress large ensembles into more efficient models.

Summary updated

BibTeX
@inproceedings{vu2025autoencoding,
  author = {Binh Duc Vu and Jan Kapar and Marvin N. Wright and David Watson},
  title = {{Autoencoding Random Forests}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=D7zMB5uEHw},
}
Figure