<jupyter_start><jupyter_text>Tabular data handling This module defines the main class to handle tabular data in the fastai library: [`TabularDataBunch`](/tabular.data.htmlTabularDataBunch). As always, there is also a helper function to quickly get your data.To allow you to easily create a [`Learner`](/basic_train.htmlLearner) for your data, it provides [`tabular_learner`](/tabular.data.htmltabular_learner).<jupyter_code>from fastai.gen_doc.nbdoc import *
from fastai.tabular import * 

show_doc(TabularDataBunch)<jupyter_output><empty_output><jupyter_text>The best way to quickly get your data in a [`DataBunch`](/basic_data.htmlDataBunch) suitable for tabular data is to organize it in two (or three) dataframes. One for training, one for validation, and if you have it, one for testing. Here we are interested in a subsample of the [adult dataset](https://archive.ics.uci.edu/ml/datasets/adult).<jupyter_code>path = untar_data(URLs.ADULT_SAMPLE)
df = pd.read_csv(path/'adult.csv')
valid_idx = range(len(df)-2000, len(df))
df.head()
cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race', 'sex', 'native-country']
dep_var = 'salary'<jupyter_output><empty_output><jupyter_text>The initialization of [`TabularDataBunch`](/tabular.data.htmlTabularDataBunch) is the same as [`DataBunch`](/basic_data.htmlDataBunch) so you really want to use the facotry method instead.<jupyter_code>show_doc(TabularDataBunch.from_df)<jupyter_output><empty_output><jupyter_text>Optionally, use `test_df` for the test set. The dependent variable is `dep_var`, while the categorical and continuous variables are in the `cat_names` columns and `cont_names` columns respectively. If `cont_names` is None then we assume all variables that aren't dependent or categorical are continuous. The [`TabularProcessor`](/tabular.data.htmlTabularProcessor) in `procs` are applied to the dataframes as preprocessing, then the categories are replaced by their codes+1 (leaving 0 for `nan`) and the continuous variables are normalized. Note that the [`TabularProcessor`](/tabular.data.htmlTabularProcessor) should be passed as `Callable`: the actual initialization with `cat_names` and `cont_names` is done during the preprocessing.<jupyter_code>procs = [FillMissing, Categorify, Normalize]
data = TabularDataBunch.from_df(path, df, dep_var, valid_idx=valid_idx, procs=procs, cat_names=cat_names)<jupyter_output><empty_output><jupyter_text>You can then easily create a [`Learner`](/basic_train.htmlLearner) for this data with [`tabular_learner`](/tabular.data.htmltabular_learner).<jupyter_code>show_doc(tabular_learner)<jupyter_output><empty_output><jupyter_text>`emb_szs` is a `dict` mapping categorical column names to embedding sizes; you only need to pass sizes for columns where you want to override the default behaviour of the model.<jupyter_code>show_doc(TabularList)<jupyter_output><empty_output><jupyter_text>Basic class to create a list of inputs in `items` for tabular data. `cat_names` and `cont_names` are the names of the categorical and the continuous variables respectively. `processor` will be applied to the inputs or one will be created from the transforms in `procs`.<jupyter_code>show_doc(TabularList.from_df)
show_doc(TabularList.get_emb_szs)
show_doc(TabularList.show_xys)
show_doc(TabularList.show_xyzs)
show_doc(TabularLine, doc_string=False)<jupyter_output><empty_output><jupyter_text>An object that will contain the encoded `cats`, the continuous variables `conts`, the `classes` and the `names` of the columns. This is the basic input for a dataset dealing with tabular data.<jupyter_code>show_doc(TabularProcessor)<jupyter_output><empty_output><jupyter_text>Create a [`PreProcessor`](/data_block.htmlPreProcessor) from `procs`.  Undocumented Methods - Methods moved below this line will intentionally be hidden<jupyter_code>show_doc(TabularProcessor.process_one)
show_doc(TabularList.new)
show_doc(TabularList.get)
show_doc(TabularProcessor.process)
show_doc(TabularList.reconstruct)<jupyter_output><empty_output>