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

Multivariate Regression and Forecasting basic tutorials throw an error #629

Closed
andreakiro opened this issue Nov 21, 2022 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@andreakiro
Copy link

andreakiro commented Nov 21, 2022

I wanted to test the library for multivariate regression and time series forecasting (single and multi steps ahead), but the very basic tutorials in the doc and in the README.md fails for both tasks and all throw the same error. The error is an AttributeError and occurs when calling the final $model.get_X_preds($args) function. Below the mentioned code, the exact error trace and my running environment details in case it proves useful.

Environment

$ python3 --version
> Python 3.10.8
$ pip3 show tsai
> Version: 0.3.4

Code snippet

from tsai.all import *

# for multivariate regression
X, y, splits = get_regression_data('AppliancesEnergy', split_data=False)
batch_tfms = TSStandardize(by_sample=True)
reg = TSRegressor(X, y, splits=splits, path='models', arch=TSTPlus, batch_tfms=batch_tfms, metrics=rmse)
reg.fit_one_cycle(100, 3e-4)
raw_preds, target, preds = reg.get_X_preds(X[splits[0]], y[splits[0]])

# for time series forecasting
ts = get_forecasting_time_series("Sunspots").values
X, y = SlidingWindow(60, horizon=$x)(ts)
splits = TimeSplitter(235)(y) 
batch_tfms = TSStandardize()
fcst = TSForecaster(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=512, arch=TSTPlus, metrics=mae)
fcst.fit_one_cycle(50, 1e-3)
raw_preds, target, preds = fcst.get_X_preds(X[splits[0]], y[splits[0]])

Error trace

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [3], line 3
      1 from tsai.inference import load_learner
      2 reg = load_learner("models/reg.pkl")
----> 3 raw_preds, target, preds = reg.get_X_preds(X[splits[0]], y[splits[0]])

File ~/miniconda3-intel/envs/tsa-310/lib/python3.10/site-packages/tsai/inference.py:17, in get_X_preds(self, X, y, bs, with_input, with_decoded, with_loss)
     15     print("cannot find loss as y=None")
     16     with_loss = False
---> 17 dl = self.dls.valid.new_dl(X, y=y, bs=bs)
     18 output = list(self.get_preds(dl=dl, with_input=with_input, with_decoded=with_decoded, with_loss=with_loss, reorder=False))
     19 if with_decoded and len(self.dls.tls) >= 2 and hasattr(self.dls.tls[-1], "tfms") and hasattr(self.dls.tls[-1].tfms, "decodes"):

File ~/miniconda3-intel/envs/tsa-310/lib/python3.10/site-packages/tsai/data/core.py:537, in NumpyDataLoader.new_dl(self, X, y, bs)
    535 if y is not None: 
    536     y = listify(y)
--> 537 ds = self.dataset.add_dataset(X, y=y)
    538 return self.new(ds, bs=min(bs, len(X)))

File ~/miniconda3-intel/envs/tsa-310/lib/python3.10/site-packages/tsai/data/core.py:489, in add_dataset(self, X, y, inplace)
    487 @patch
    488 def add_dataset(self:NumpyDatasets, X, y=None, inplace=True):
--> 489     return add_ds(self, X, y=y, inplace=inplace)
...

File ~/miniconda3-intel/envs/tsa-310/lib/python3.10/site-packages/tsai/data/core.py:120, in ToFloat.encodes(self, o)
--> 120 def encodes(self, o): return o.astype(np.float32)

AttributeError: 'list' object has no attribute 'astype'
@andreakiro andreakiro changed the title Multivariate Regression and Forecasting basic tutorials throws an error Multivariate Regression and Forecasting basic tutorials throw an error Nov 21, 2022
@oguiza oguiza added the bug Something isn't working label Nov 21, 2022
oguiza added a commit that referenced this issue Nov 21, 2022
@oguiza
Copy link
Contributor

oguiza commented Nov 21, 2022

Hi @andreakiro,

Thank you for raising this issue. It's indeed a bug.
I've already fixed it in GitHub. If you use the pip install from GitHub method and rerun your code it should work well:

   pip install git+https://github.com/timeseriesAI/tsai.git

You can see the test in this gist.

It'd be good if you can test it works and close the issue.

@andreakiro
Copy link
Author

Yes, it now works on my machine as well, thanks for the super quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants