Fastai v2 tabular

Hi,

  1. while trying to do regression on my own data with tabular_learner I am getting AssertionError: Could not infer loss function from the data, please pass a loss function (see detailed error output below)

  2. Following to the previous broblem, when I specify loss_func=mse I get extreme train_loss and valid_loss, while fastai v1 works fine with the same data.

  3. TabularPandas object takes ages to create, while fastai v1 TabularList is quick.

I would appreciate your help. Thank you!

from fastai2.tabular.all import *

path = Path('tutorial_learn_path')

cont,cat = cont_cat_split(df, max_card=700, dep_var='price')
valid_inxs = set_.sample(int(len(df)/5)).index
splits = IndexSplitter(list(valid_inxs))(range_of(df))
procs = [Categorify, FillMissing, Normalize]

to = TabularPandas(df, procs, cat, cont, y_names=name, splits=splits)
dls = to.dataloaders(bs=64)
learn = tabular_learner(dls, metrics=rmse)
learn.fit_one_cycle(10, 1e-3)

error message:

AssertionError Traceback (most recent call last)
in
----> 1 learn = tabular_learner(dls, metrics=rmse)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/tabular/learner.py in tabular_learner(dls, layers, emb_szs, config, n_out, y_range, ps, embed_p, use_bn, bn_final, bn_cont, **kwargs)
35 model = TabularModel(emb_szs, len(dls.cont_names), n_out, layers, ps=ps, embed_p=embed_p,
36 y_range=y_range, use_bn=use_bn, bn_final=bn_final, bn_cont=bn_cont, **config)
—> 37 return TabularLearner(dls, model, **kwargs)
38
39 # Cell

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/learner.py in init(self, dls, model, loss_func, opt_func, lr, splitter, cbs, metrics, path, model_dir, wd, wd_bn_bias, train_bn, moms)
78 if loss_func is None:
79 loss_func = getattr(dls.train_ds, ‘loss_func’, None)
—> 80 assert loss_func is not None, “Could not infer loss function from the data, please pass a loss function.”
81 self.loss_func = loss_func
82 self.path = path if path is not None else getattr(dls, ‘path’, Path(’.’))

AssertionError: Could not infer loss function from the data, please pass a loss function.

1 Like