Please could someone assist with 2 queries. 1. I a...
# statsforecast
t
Please could someone assist with 2 queries. 1. I am getting an error when directly forecast with statsforecast with the following code:
Copy code
# define model(s)
ts_models = [
        AutoETS(model=['Z','Z','Z'], season_length=season, alias='AE')
    ]


# Instantiate StatsForecast class
model = StatsForecast(df = train,
                    models=ts_models,
                      freq = 'H',
                      n_jobs=-1)


# Forecast
forecast = model.forecast(h=1500, level=[95])
Error: _‘StatsForecast’ object has no attribute ‘fitted_’_ However if I use the fit and predict methods with the code below, the forecast is successful.
Copy code
# plot data
StatsForecast.plot(train, engine='plotly')

# define model(s)
ts_models = [
        AutoETS(model=['Z','Z','Z'], season_length=season, alias='AE')
    ]


# Instantiate StatsForecast class
model = StatsForecast(
                    models=ts_models,
                      freq = 'H',
                      n_jobs=-1)

model.fit(train)

# Forecast
h = round((valid['ds'].nunique()) * 0.5)
forecast = model.predict(h=h, level=[95])

model.plot(df, forecast, engine='plotly')
Any ideas why the more efficient forecast method is not working in my case? 2. And a secondary issue, is that the StatsForecast.plot() is also not working when I run in a script in PyCharm. If anyone has guidance on this second query it would be appreciated.
m
Hi @Toni Borders I noticed that when you use the forecast method, the forecast horizon is 1500. Then, in the fit and predict method, the horizon is defined as
h = round((valid['ds'].nunique()) * 0.5)
Is this also equal to 1500?
also, please make sure that you're using the latest version of statsforecast, since the forecast method should produce the same result as fit & predict.
t
it is also equal to roughly 1500. Let me try to change it explicitly….
I have changed the code such that the inputs to the forecast method replicate exactly what is in the fit/predict method and I still get and error, albeit a different error.
Copy code
Traceback (most recent call last):
  File "/<path>/<my_script>.py", line 297, in <module>
    main(data)
  File "/<path>/<my_script>.py", line 277, in main
    forecast, model_aliases = forecast_only(dfUsage_clean, season)
  File "/<path>/<my_script>.py", line 125, in forecast_only
    forecast = model.forecast(h=h, level=[95])
  File "<site-packages_path>/statsforecast/core.py", line 1899, in forecast
    return super().forecast(
  File "<site-packages_path>/statsforecast/core.py", line 1097, in forecast
    res_fcsts = self._forecast_parallel(h=h, fitted=fitted, X=X, level=level)
  File "<site-packages_path>/statsforecast/core.py", line 1376, in _forecast_parallel
    gas, Xs = self._get_gas_Xs(X=X)
  File "<site-packages_path>/statsforecast/core.py", line 1315, in _get_gas_Xs
    gas = self.ga.split(self.n_jobs)
AttributeError: 'StatsForecast' object has no attribute 'ga'
I am on StatsForecast 1.6.0, which I think is the most recent version…
Any thoughts @Mariana Menchero?
j
Can you try providing the df to forecast? e.g.
model.forecast(df=train, h=h, level=[95])
t
That was it. Thanks very much @José Morales !