Tabular RuntimeError

Hello. I’m trying to run my own data according to the lesson 4 tabular data.

I get to the point of the, 1e-2) and it runs through an epic, but errors out when it starts to run the test percentage. I have no idea why. the below is my code and traceback error.

dep_var = ‘scalar_coupling_constant’

cat_names = [‘type’, ‘atom_index_closest_0’,‘atom_index_closest_1’]

cont_names = [‘x_0’, ‘y_0’, ‘z_0’, ‘x_1’, ‘y_1’, ‘z_1’, ‘dx’, ‘dy’, ‘dz’, ‘distance’, ‘x_closest_0’, ‘y_closest_0’
, ‘z_closest_0’, ‘distance_closest_1’, ‘x_closest_1’, ‘y_closest_1’, ‘z_closest_1’,‘distance_0’
, ‘distance_1’, ‘cos_0_1’, ‘cos_0’, ‘cos_1’]

procs = [FillMissing, Categorify, Normalize]

test_data = TabularList.from_df(test, cat_names=cat_names, cont_names = cont_names, procs = procs)

data = (TabularList.from_df(train, cat_names=cat_names, cont_names = cont_names, procs = procs)

data.show_batch(rows = 10)

learn = tabular_learner(data, layers = [200,100], metrics = accuracy), 1e-2)

This is the error:

RuntimeError Traceback (most recent call last)
----> 1, 1e-2)

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in fit(self, epochs, lr, wd, callbacks)
198 callbacks = [cb(self) for cb in self.callback_fns + listify(defaults.extra_callback_fns)] + listify(callbacks)
199 if defaults.extra_callbacks is not None: callbacks += defaults.extra_callbacks
–> 200 fit(epochs, self, metrics=self.metrics, callbacks=self.callbacks+callbacks)
202 def create_opt(self, lr:Floats, wd:Floats=0.)->None:

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in fit(epochs, learn, callbacks, metrics)
104 if not cb_handler.skip_validate and not
105 val_loss = validate(learn.model,, loss_func=learn.loss_func,
–> 106 cb_handler=cb_handler, pbar=pbar)
107 else: val_loss=None
108 if cb_handler.on_epoch_end(val_loss): break

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in validate(model, dl, loss_func, cb_handler, pbar, average, n_batch)
61 if not is_listy(yb): yb = [yb]
62 nums.append(first_el(yb).shape[0])
—> 63 if cb_handler and cb_handler.on_batch_end(val_losses[-1]): break
64 if n_batch and (len(nums)>=n_batch): break
65 nums = np.array(nums, dtype=np.float32)

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in on_batch_end(self, loss)
306 “Handle end of processing one batch with loss.”
307 self.state_dict[‘last_loss’] = loss
–> 308 self(‘batch_end’, call_mets = not self.state_dict[‘train’])
309 if self.state_dict[‘train’]:
310 self.state_dict[‘iteration’] += 1

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in call(self, cb_name, call_mets, **kwargs)
248 “Call through to all of the CallbakHandler functions.”
249 if call_mets:
–> 250 for met in self.metrics: self._call_and_update(met, cb_name, **kwargs)
251 for cb in self.callbacks: self._call_and_update(cb, cb_name, **kwargs)

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in _call_and_update(self, cb, cb_name, **kwargs)
239 def call_and_update(self, cb, cb_name, **kwargs)->None:
240 “Call cb_name on cb and update the inner state.”
–> 241 new = ifnone(getattr(cb, f’on
{cb_name}’)(**self.state_dict, **kwargs), dict())
242 for k,v in new.items():
243 if k not in self.state_dict:

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in on_batch_end(self, last_output, last_target, **kwargs)
342 if not is_listy(last_target): last_target=[last_target]
343 self.count += first_el(last_target).size(0)
–> 344 val = self.func(last_output, *last_target)
345 if
346 val = val.clone()

C:\ProgramData\Anaconda3\lib\site-packages\fastai\ in accuracy(input, targs)
28 input = input.argmax(dim=-1).view(n,-1)
29 targs = targs.view(n,-1)
—> 30 return (input==targs).float().mean()
32 def accuracy_thresh(y_pred:Tensor, y_true:Tensor, thresh:float=0.5, sigmoid:bool=True)->Rank0Tensor:

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ‘other’

If you are trying to do a regression based task (which I assume it looks like you are as the dependent variable is a scalar) you want to follow the Rossmann notebook instead from lesson 6 in making your DataBunch.