Binary Split Categorical feature with Mean Absolute Error Criteria in CART

Peng Yu, Yike Chen, Chao Xu, Albert Bifet, Jesse ReadarXiv 2025 · DOI

Abstract

In Classification and Regression Trees (CART), splitting categorical features with high cardinality is a significant computational challenge. While the Mean Squared Error (MSE) criterion benefits from an efficient sorting-based heuristic, no such optimal shortcut was previously known for the Mean Absolute Error (MAE) criterion. This paper proves that standard numerical encodings are insufficient for MAE and introduces the Unimodal Cost 2-Median (UC2M) algorithm. UC2M finds the mathematically optimal split in $O(n \log n)$ time, providing a solution that is both faster and more accurate than the heuristics implemented in state-of-the-art libraries like LightGBM.

Introduction

Handling categorical features such as "City" or "Product Type" in decision trees requires partitioning $k$ categories into two groups. The search space for an optimal binary split grows exponentially as $2^{k-1} - 1$, making exhaustive search infeasible for large $k$. For MSE, sorting categories by their mean target value reduces the search to $k-1$ candidates. However, MAE is often preferred for its robustness to outliers and skewed data. This paper addresses the lack of an efficient, exact splitting algorithm for MAE.

Theoretical Limitations: The "No-Go" Theorem

A common practice in machine learning is to encode categorical variables numerically (e.g., using the median target value) and then treat them as continuous. The authors mathematically prove that no such unsupervised numerical encoding can consistently identify the optimal MAE split. Specifically, they demonstrate that the popular "median heuristic" can lead to split errors up to twice as large as the true optimum. This finding highlights a fundamental difference between how MSE and MAE behave in the context of tree-based models.

The UC2M Algorithm

To overcome these limitations, the authors reformulate the categorical split problem as a geometric optimization task known as the Unimodal Cost 2-Median (UC2M) problem. The proposed solution relies on three key technical innovations:

  1. Total Monotonicity: The cost matrix associated with the split candidates is proven to be totally monotone, enabling efficient search strategies.
  2. The $\dagger$ (Dagger) Transform: A novel piecewise-linear transformation is introduced to prune the search space by skipping irrelevant calculations.
  3. Divide and Conquer Strategy: By utilizing a specialized divide-and-conquer approach, the algorithm achieves a complexity of $O(n \log n + k \log k \log n)$, where $n$ is the number of samples and $k$ is the number of categories.

Experimental Evaluation

The algorithm was benchmarked against LightGBM using several real-world regression datasets from OpenML and Kaggle. These include high-cardinality datasets like Predict Droughts (7,588 categories) and delays_zurich_transport, as well as smaller datasets like diamonds and boston.

Key Results

The experimental results confirm that the UC2M algorithm is not only mathematically optimal but also computationally superior to existing heuristics.

Running time comparison between the proposed algorithm and LightGBM.

As shown in the figure above, the proposed algorithm scales nearly linearly with the number of data points and maintains a significant speed advantage over LightGBM. For instance, on the Predict Droughts dataset, the algorithm completed the split in 0.94 seconds, compared to 5.4 seconds for LightGBM.

Performance metrics across various datasets.

The table above details the performance across diverse datasets. Notably, LightGBM's heuristic often fails to find the optimal split, reaching as low as 61.9% relative accuracy on the diamonds dataset. In contrast, the UC2M algorithm consistently finds the optimal split while being orders of magnitude faster on smaller datasets and significantly faster on large-scale data.

Conclusion

This work bridges the gap between machine learning and computational geometry by providing an exact, efficient algorithm for MAE-based categorical splitting. By proving the inadequacy of standard heuristics and delivering a faster, optimal alternative, the authors provide a robust tool for building more accurate decision trees on skewed or outlier-prone data. Future research will explore the cumulative impact of these optimal splits on the performance of ensemble methods like Random Forests and Gradient Boosted Trees.

Summary updated

BibTeX
@misc{yu2025binary,
  author = {Peng Yu and Yike Chen and Chao Xu and Albert Bifet and Jesse Read},
  title = {{Binary Split Categorical feature with Mean Absolute Error Criteria in CART}},
  year = {2025},
  eprint = {2511.08470},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.08470},
}
Figure