from fastai.tabular.data import *
The main function you probably want to use in this module is tabular_learner. It will automatically create a TabularModel suitable for your data and infer the right loss function. See the tabular tutorial for an example of use in context.
It works exactly as a normal Learner, the only difference is that it implements a predict method specific to work on a row of data.
If your data was built with fastai, you probably won't need to pass anything to emb_szs unless you want to change the default of the library (produced by get_emb_sz), same for n_out which should be automatically inferred. layers will default to [200,100] and is passed to TabularModel along with the config.
Use tabular_config to create a config and customize the model used. There is just easy access to y_range because this argument is often used.
All the other arguments are passed to Learner.
path = untar_data(URLs.ADULT_SAMPLE)
df = pd.read_csv(path/'adult.csv')
cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race']
cont_names = ['age', 'fnlwgt', 'education-num']
procs = [Categorify, FillMissing, Normalize]
dls = TabularDataLoaders.from_df(df, path, procs=procs, cat_names=cat_names, cont_names=cont_names,
y_names="salary", valid_idx=list(range(800,1000)), bs=64)
learn = tabular_learner(dls)
We can pass in an individual row of data into our TabularLearner's predict method. It's output is slightly different from the other predict methods, as this one will always return the input as well:
row, clas, probs = learn.predict(df.iloc[0])
row.show()
clas, probs