facebookresearch / Kats

Kats, a kit to analyze time series data, a lightweight, easy-to-use, generalizable, and extendable framework to perform time series analysis, from understanding the key statistics and characteristics, detecting change points and anomalies, to forecasting future trends.
MIT License
4.88k stars 534 forks source link

Tutorial 201 throws error for VARModel #161

Closed samgalen closed 2 years ago

samgalen commented 2 years ago

Hi everyone,

Trying to do multi-variate time series forecasting. When I try to run the code blocks using the VARModel in the tutorial 201, I get an error.

The code I run is

# replicating the demo
multi_df = pd.read_csv("./data/multi_ts.csv")
multi_ts = TimeSeriesData(multi_df)
params = VARParams()
m = VARModel(multi_ts, params)
m.fit()
fcst = m.predict(steps=90)

m.plot()
plt.show()

which produces

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-53-b1c4cc4ad2f3> in <module>
      5 m = VARModel(multi_ts, params)
      6 m.fit()
----> 7 fcst = m.predict(steps=90)
      8 
      9 m.plot()

~/.local/lib/python3.8/site-packages/kats/models/var.py in predict(self, steps, include_history, **kwargs)
    149         # pyre-fixme[16]: `VARModel` has no attribute `model`.
    150         fcst = self.model.forecast_interval(
--> 151             y=self.model.y, steps=steps, alpha=self.alpha
    152         )
    153         logging.info("Generated forecast data from VAR model.")

~/.local/lib/python3.8/site-packages/statsmodels/base/wrapper.py in __getattribute__(self, attr)
     32             pass
     33 
---> 34         obj = getattr(results, attr)
     35         data = results.model.data
     36         how = self._wrap_attrs.get(attr)

AttributeError: 'VARResults' object has no attribute 'y'
hattajr commented 2 years ago

Hi, did you solve the problem?

justinkuan commented 2 years ago

Hi, did you solve the problem?

@hattajr , I just replied to someone else about how I resolved this problem since I had the same error. The problem lies in kats, which needs to be updated for the newer version of statsmodel. The missing y is because y was deprecated and removed in a later version (0.13).

Try installing statsmodel==0.12.2 (the version specified in requirements.txt) and see if that resolves the problem.

If you look under Properties on the following two links, you'll notice that y disappears in v13: statsmodel v0.12.2 VARResults statsmodel v0.13.0 VARResults

Once you reload and run it, if it works, you may see a warning saying "FutureWarning: y is a deprecated alias for endog, will be removed in version 0.11.0"