Explain that TabICL predictors are actually an ensemble.
Speed up inference by reducing ensemble size.
You can use tabular foundation models like TabICL also for regression. The regression foundation models are based on different pretraining, and a slightly different architecture, but otherwise, feel and look are very similar to classification.
Let’s use TabICL to make predictions.
Let’s predict wine quality
We will predict the quality of wines based on their physical and chemical properties like alcohol content and acidity. We use the Wine Quality dataset (Cortez et al. 2009) from the UCI Machine Learning Repository, which collects red and white vinho verde samples from northern Portugal.
Let’s load the dataset and create a train-test split.
By default, TabICL predicts the mean of the predictive distribution. TabICL makes it super easy to instead predict the median by simply changing one parameter:
But again, thanks to the scikit-learn interface, TabICL usage feels very similar to traditional ML, even though we don’t train the model with fit, and predict does in-context learning.
Let’s evaluate the model, and also compare it with a CatBoost tree ensemble.
TabICL versus CatBoost
To compare TabICL against CatBoost (Prokhorenkova et al. 2018), let’s tune CatBoost’s most commonly tuned hyperparameters with random search:
In all three metrics, TabICL beats the CatBoost ensemble. This is of course not guaranteed to happen, but benchmarks have shown that tabular foundation models often best boosted tree ensembles, the previously strongest models in the tabular space. But did you know that our TabICL regressor is an ensemble, too?
TabICL is an ensemble
When calling reg.predict, the function actually returns an average prediction across an ensemble of 8 TabICL predictions for each row.
That might be a quite puzzling fact at first: How do the predictions differ, and what is the motivation for ensembling predictions of TFMs? Ensembling is typically used to improve predictive performance, and make predictions more robust. Performance and robustness are also the motivation behind TabICL ensembling.
A good ensemble is built on variety: it benefits from diversity of the underlying ensemble members, aka ML models. So, where is the variety coming from between two different TabICL models in this ensemble? There are a couple of knobs that can be randomized to create prediction diversity (three for classification):
The order of the features, which may be re-arranged by circular shifts, random permutation, Latin square, or kept as-is.
The feature pre-processing transformation used. Default is to pick between the Yeo-Johnson power transformation (Yeo and Johnson 2000), and no transformation.
For classification, the order of the class labels may be randomized.
But why does shuffling the features create diversity? Sounds … bad. And, indeed, it’s an artifact of an architectural choice of TabICL and other tabular foundation models. The attention mechanism can’t distinguish features that have the same marginal distribution (i.e. same means, same variance, …), and to counteract that, features are grouped within the architecture. But that also means that the predictions depend on the order of features. That also makes ensembling not only a fun option, but, conceptually, there is no “right” order of features, so it makes sense to smooth that out by averaging over various feature orders.
Trading accuracy for speed with n_estimators
By default, the prediction is averaged over doing 8x TabICL in-context learning with different pre-processing and feature orders (and class label order, in case of classification). Since prediction is the expensive step with tabular foundation models, this also means reducing ensemble size is a huge cost lever. A lever that can reduce prediction time by a factor of roughly 8.
Try reducing n_estimators
With the default being 8 estimators, there is an up to 8x inference speed improvement. It’s always worth trying out using fewer estimators in the ensemble.
But this comes at a price: Reducing ensemble sizes sometimes reduces predictive performance and robustness. Since this may differ between tasks and applications, it’s always worth trying out. Let’s see whether and how the performance suffers and prediction time improves when we reduce the ensemble size for the wine quality prediction.
from time import perf_counterresults = []for n in [1, 2, 4, 8]: reg = TabICLRegressor(n_estimators=n, random_state=1) reg.fit(X_train, y_train) start = perf_counter() pred = reg.predict(X_test) elapsed = perf_counter() - start results.append({"n_estimators": n,"predict (s)": elapsed,**regression_score(y_test, pred), })df = pd.DataFrame(results).set_index("n_estimators")df.round(3)
Effect of reducing TabICL ensemble size on prediction time and performance.
For the wine data, it seems that actually having just one TabICL in-context pass is enough, no need for a varied ensemble. And an easy way to reduce compute time by roughly 87.5%!
Cortez, Paulo, António Cerdeira, Fernando Almeida, Telmo Matos, and José Reis. 2009. “Modeling Wine Preferences by Data Mining from Physicochemical Properties.”Decision Support Systems 47 (4): 547–53. https://doi.org/10.1016/j.dss.2009.05.016.
Prokhorenkova, Liudmila, Gleb Gusev, Aleksandr Vorobev, Anna Veronika Dorogush, and Andrey Gulin. 2018. “CatBoost: Unbiased Boosting with Categorical Features.” In Advances in Neural Information Processing Systems (NeurIPS). Vol. 31. https://doi.org/10.48550/arXiv.1706.09516.
Yeo, In-Kwon, and Richard A. Johnson. 2000. “A New Family of Power Transformations to Improve Normality or Symmetry.”Biometrika 87 (4): 954–59. https://doi.org/10.1093/biomet/87.4.954.