Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type issue when using get_tabular_learner for regression problem #835

Closed
harvitronix opened this issue Oct 4, 2018 · 2 comments
Closed

Comments

@harvitronix
Copy link

I'm trying to run a regression on a dataframe with categorical and continuous columns using the get_tabular_learner() helper. My code is as follows:

df = pd.read_csv(DATA_PATH)
dep_var = 'actual'

train_df, valid_df = df[:10000].copy(), df[10000:].copy()

data = tabular_data_from_df('.', train_df, valid_df, dep_var, tfms=[Categorify], cat_names=CAT_NAMES, cont_names=CONT_NAMES)

learn = get_tabular_learner(data, layers=[200,100])
learn.loss_fn = F.mse_loss
learn.fit(1)

Running this gives me an error with the loss function:

File "/home/harvitronix/.local/lib/python3.6/site-packages/fastai/basic_train.py", line 25, in loss_batch
    loss = loss_fn(out, *yb)
  File "/home/harvitronix/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 1808, in mse_loss
    return _pointwise_loss(lambda a, b: (a - b) ** 2, torch._C._nn.mse_loss, input, target, reduction)
  File "/home/harvitronix/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 1770, in _pointwise_loss
    return lambd_optimized(input, target, _Reduction.get_enum(reduction))
RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'target'

I'm unclear if this is a bug or implementation error. Guidance is appreciated.

@jandremarais
Copy link

jandremarais commented Oct 4, 2018

What happens if you add log_output=True to tabular_data_from_df and change layers argument to [200, 1]?

Edit:

Or if you don't want log_output=True, you can hack at it this way:

def myloss(input, target): return F.mse_loss(input, target.float())
learn.loss_fn = myloss

Not sure where to tell the learner that it is a regression model.

@jph00
Copy link
Member

jph00 commented Oct 4, 2018

Can you please ask this question on the forums?

@jph00 jph00 closed this as completed Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants