liveBook · Manning

Fastai tabular

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

fastai tabular is a fastai component providing tabular deep learning models and utilities.

fastai tabular provides a practical workflow for deep learning on tabular data: identify categorical and continuous columns, define the target, prepare data loaders, and train a model. An Airbnb NYC listing-price prediction workflow demonstrates the approach in a Jupyter notebook. section 8.2.1

A typical fastai tabular workflow includes:

  • Import fastai and fastbook utilities, then identify the dependent variable and categorical and continuous columns. section 8.2.1
  • Convert a classification target to string values so fastai selects cross-entropy rather than mean squared error. section 8.2.1
  • Create TabularDataLoaders with FillMissing, Categorify, and Normalize, while specifying validation rows and batch size. section 8.2.1
  • Train with tabular_learner and fit_one_cycle, then inspect batches, training results, the selected loss, and the model summary. section 8.2.1

Diagnosing a misleading training run

If the target remains numeric when the task requires classification, training can produce stagnant accuracy and fastai can select MSELoss. Converting the target to strings leads to CrossEntropyLoss and provides the intended classification setup. section 8.2.1

Listing 8.5 Defining the TabularDataLoaders object
path = '.'                                                #1
procs = [FillMissing,Categorify, Normalize]               #2
dls = TabularDataLoaders.from_df(dtrain,                  #3
                                 path,
                                 procs= procs,            #4
                                 cat_names= cat,          #5
                                 cont_names = cont,       #6
                                 y_names = dep_var,       #7
                                 valid_idx=\
list(range((merged_data.shape[0]-10000),
merged_data.shape[0])),                                   #8
                                 bs=32)                   #9

Use the complete TabularDataLoaders definition to see how preprocessing, column roles, validation indices, and batch size fit together. section 8.2.1

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Explains imports, target typing, preprocessing, data loading, training, diagnostics, and summaries without detailing model internals.
Examples
Uses Airbnb NYC listings, column-role definitions, data-loader code, batch displays, training output, and loss-function inspection.
What it assumes
Assumes a tabular dataset and Jupyter notebook context while making column roles and preprocessing explicit.
What you can do after
Build a fastai tabular training pipeline and diagnose target-type and loss-function mistakes.
How it connects
Connects tabular data with categorical variables, continuous variables, data loaders, classification, preprocessing, loss functions, and PyTorch.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.