Module 12 β€” DeepTab (optional)ΒΆ

Goal: Meet the modern deep-learning toolkit for structured data. Gradient-boosted trees (XGBoost/LightGBM) still win most tabular problems β€” but DeepTab (OpenTabular/DeepTab) wraps 15 deep architectures (Mamba, FT-Transformer, SAINT, NODE, TabM, ResNet…) behind a clean scikit-learn API, and unlocks things trees can’t: distributional regression, learned embeddings, and end-to-end multimodal models.

Estimated time: 1–2 hours.

Prerequisites: Module 5 (NB 17 sklearn basics, NB 19 feature engineering) and PyTorch basics β€” either the Module 5 appendices A1–A3 or the full Module 6 (its NB 22 builds this module’s entity-embedding architecture by hand). Appendix A5 (conformal prediction) pairs naturally with the uncertainty section.

        scikit-learn API  ──►  15 deep tabular architectures
        model.fit(X, y)        Mambular Β· FTTransformer Β· SAINT Β· NODE
        model.predict(X)       TabM Β· ResNet Β· MLP Β· TabTransformer …
        model.predict_proba    each ships as  *Classifier / *Regressor / *LSS
        model.encode(X)
              β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β–Ό          β–Ό                     β–Ό                         β–Ό
 classify   regress           distributional (LSS)      latent embeddings
                              predict a whole            feed into any
                              distribution, not          downstream model
                              just a point

Notebook at a glanceΒΆ

#

Notebook

⏱ Time

Difficulty

What you’ll build

38

44_deeptab_tabular_deep_learning.ipynb

~60–90 min

Intermediate β†’ Advanced

One customer-churn table, many tools through one socket: a churn classifier benchmarked against a HistGradientBoosting baseline, a revenue regressor, a distributional (LSS) model with an uncertainty band, row embeddings via .encode(), and two ways to tune β€” all through DeepTab’s sklearn-style API

Notebook guideΒΆ

44 Β· DeepTab: Deep Learning for Tabular Data β€” 44_deeptab_tabular_deep_learning.ipynbΒΆ

For two decades, tabular data β€” the spreadsheets, transaction logs and feature stores that run most of a business β€” has belonged to gradient-boosted trees. The notebook opens by taking that seriously: on the median tabular benchmark, XGBoost/LightGBM are still the thing to beat. But architectures designed specifically for tables β€” FT-Transformer, SAINT, NODE, TabM, ResNet, and sequence models such as Mamba β€” now match or beat boosting on large, complex datasets, and they natively do things trees cannot: predict full distributions, learn reusable row embeddings, fuse tables with text/image towers, and transfer-learn across tables. DeepTab (from the OpenTabular project) wraps 15 stable models behind a single scikit-learn BaseEstimator API, each shipping as a matching <Name>Classifier / <Name>Regressor / <Name>LSS trio.

The notebook’s mental model is one socket, many power tools: the sklearn .fit/.predict interface is the wall socket, the gradient-boosted tree is the trusty cordless drill you grab first, and DeepTab’s architectures are specialist tools that plug into the same socket β€” swapping MambularClassifier for FTTransformerClassifier is a one-word change. A single synthetic customer-churn frame (tenure, monthly charges, support tickets, contract type, region) runs through every section: you predict churn, predict revenue, get an uncertainty band, and pull row embeddings from it.

It also showcases DeepTab v2’s split-config API: instead of one long list of keyword arguments, a model is configured through three small objects β€” MambularConfig (architecture), PreprocessingConfig (input handling) and TrainerConfig (the training loop) β€” and because everything is a BaseEstimator, nested params like model_config__d_model drop straight into RandomizedSearchCV.

Learning objectives:

  • Decide when a tabular deep-learning model is worth it versus a gradient-boosted tree (spoiler: try the trees first)

  • Train a classifier and a regressor with DeepTab’s sklearn-style .fit / .predict / .predict_proba API, and swap architectures by name

  • Use distributional regression (LSS) to predict full distributions and reason about uncertainty for risk and pricing

  • Extract latent embeddings with .encode() and feed them to a downstream model

  • Tune hyperparameters with both DeepTab’s built-in optimize_hparams and sklearn’s RandomizedSearchCV

Sections (the notebook’s arc, group by group):

Setup & the offline gate

  • πŸ”Œ Smoke test: is DeepTab installed? β€” imports deeptab and sets the single HAS_DEEPTAB flag every later cell branches on

  • The offline stand-in β€” drop-in classes with DeepTab v2’s exact constructors and methods, backed by small sklearn neural nets

  • One factory, two backends β€” make_classifier(...) & friends return real or stand-in models, so the rest of the notebook never needs another if HAS_DEEPTAB

Why β€” and on what data

  • 1 Β· The value proposition β€” and when not to use it β€” the β€œstart with gradient boosting” discipline: the drill already in your hand

  • 2 Β· A synthetic business dataset (churn) β€” build and eyeball the mixed-type table (tenure/charges/tickets + contract/payment/region)

The core sklearn-style API

  • 3 Β· Classification with MambularClassifier β€” honest HistGradientBoosting baseline first, then the deep model, then swapping the architecture by class name (βœ‹ threshold tuning for churn)

  • 4 Β· Regression with MambularRegressor β€” same socket, continuous revenue target

What trees can’t do natively

  • 5 Β· Distributional regression (LSS) with MambularLSS β€” why a distribution beats a point estimate; per-row (mean, Οƒ) for risk/pricing/inventory (βœ‹ stock to the 90th percentile)

  • 6 Β· Latent embeddings via model.encode(X) β€” dense row vectors for similarity search and downstream models (βœ‹ find the most similar customer)

Making it good

  • 7 Β· Hyperparameter tuning β€” (a) built-in Bayesian optimize_hparams, (b) sklearn RandomizedSearchCV with nested model_config__d_model params

  • πŸ§ͺ Exercises Β· 🧠 Key takeaways Β· βœ… Self-assessment Β· πŸš€ Next step

Models covered: MambularClassifier, MambularRegressor, MambularLSS trained in-notebook, each configured via the v2 split-config trio (MambularConfig + PreprocessingConfig + TrainerConfig); one-line-swap siblings named for every architecture (FTTransformerClassifier, TabTransformerClassifier, ResNetClassifier, MLPClassifier, SAINTClassifier, TabMClassifier, NODEClassifier, …); HistGradientBoostingClassifier as the tree baseline to beat.

Practice: 3 βœ‹ quick exercises (~2 min each, collapsible solutions) β€” threshold tuning for churn, stock to the 90th percentile, find the most similar customer β€” plus 6 end-of-notebook πŸ§ͺ exercises (architecture bake-off, bigger data, Poisson vs normal LSS families, embeddings-for-retrieval, real tuning, and a conformal-prediction stretch pairing with NB A5). Reference-style module, so exercises are a numbered list β€” no ⭐ ratings, Debug-me or 🎁 mini-project here.

Datasets: one synthetic customer-churn table (400 rows), generated inline with make_classification plus categorical contract / payment / region columns and an engineered churn signal; a continuous revenue target derived from it powers the regression and LSS sections. Nothing is downloaded.

Offline behaviour: the whole notebook branches on a single HAS_DEEPTAB flag. Without deeptab installed, drop-in stand-in classes mimic the v2 estimators β€” same split-config constructors and methods, backed by sklearn MLPClassifier/MLPRegressor behind an ordinal encoder; .encode() returns last-hidden-layer activations, the LSS stand-in returns per-row (mean, Οƒ) with a constant residual Οƒ, and optimize_hparams is a no-op. pip install deeptab (pulls PyTorch + Lightning) swaps in the real Mamba/Transformer models with no other code changes.

Folder artifactsΒΆ

lightning_logs/ (version_0…3) and model_checkpoints/ (best_model*.ckpt) are by-products of running the notebook with the real deeptab installed β€” PyTorch Lightning writes training logs and best-model checkpoints there. Safe to browse or delete; they regenerate on the next real training run.

How this notebook worksΒΆ

Module 12 is optional and written in the reference style of the appendices: it focuses on seeing a library at work, with βœ‹ checkpoint exercises (collapsible solutions) at the key decision points rather than a drill-heavy exercise block. It runs 100% offline end-to-end β€” the sklearn stand-in keeps every cell executable so you can study the API shape and the GBMs-first reasoning now, and installing deeptab later upgrades the same code to the genuine deep models:

pip install deeptab     # optional β€” pulls torch + lightning

The disciplines the notebook keeps hammering:

  • Try gradient boosting first. On small/medium tabular data, a tuned GBM is usually the bar to beat β€” on the 400-row churn table it holds its own, exactly as the rule predicts. Deep tabular models earn their keep with large data, multimodal inputs, transfer, or distributional needs.

  • Predict distributions, not just points. For pricing, risk, demand and inventory, the spread matters as much as the mean β€” that’s what the *LSS variants give you. Pair with conformal prediction (A5) for calibrated intervals.

  • One API, many architectures. Swapping MambularClassifier β†’ FTTransformerClassifier is a one-word change β€” so benchmark several, don’t marry the first.

Where nextΒΆ

β†’ This is the end of the optional track. Loop back to Module 5 β€” Machine Learning (../05_machine_learning/) to compare against tree ensembles, or to Module 7 β€” Industry Applications (../07_industry_applications/) to put churn/demand/risk models into a business context.