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
