Skip to content

STLForecastResults.get_prediction() with ETSModel as model fails when "trend"="mul" in the model kwargs #7309

Closed

Description

@StanislasGuinel

I get an error when calling the get_prediction() method on a STLForecastResults object that is the output of STLForecast(endog=data, model=ETSModel, model_kwargs={'trend': 'mul'}).fit()

self.forecast_variance = (

self.forecast_variance is not defined when self.method == "simulated"
but get_prediction() calls pred.var_pred_mean that uses self.forecast_variance
mean, pred.var_pred_mean, dist="norm", row_labels=pred.row_labels,

Activity

  1. AnupamPandey1924 commented on Mar 3, 2021

    @AnupamPandey1924

    Stlf_model = STLForecast( ts, model =ARIMA, model_kwargs ={ 'order': (2,1,0)}, period =52)

    Stlf_model = Stlf_model.fit()

    Stlf_model.get_prediction() gives the following error

    ' Data must be 1-dimensional'

    However, Stlf_model.forecast() runs fine.

    But I need to get the corresponding confidence interval of the forecasted values

  2. bashtage commented on Mar 3, 2021

    @bashtage
    Member

    Can you provide a complete, copy-pastable example that reproduces?

  3. AnupamPandey1924 commented on Mar 3, 2021

    @AnupamPandey1924

    Hi,

    I am using the following code (data attached)

    import pandas as pd
    from statsmodels.tsa.forecasting.stl import STLForecast
    from statsmodels.tsa.arima.model import ARIMA

    ts = pd. read_csv('../ts_example.csv')
    ts = ts.set_index('Date')
    ts = ts.resample('W-SUN').interpolate(method='linear')
    ts = ts.sort_index()

    stlf_model = STLForecast(endog=ts,model = ARIMA,model_kwargs= { 'order':(2,1,0)}, period = 52)
    stlf_model = stlf_model.fit()
    forecast = stlf_model.forecast(26)

    stlf_model.get_prediction() —- throws an error

    ts_example.zip

  4. added 2 commits that reference this issue on Mar 17, 2021
    0ef2187
    a0e8475
  5. rashmisoni20 commented on Jun 25, 2021

    @rashmisoni20

    Hi,

    I am trying to run below code, but getting error:

    import pandas as pd
    import numpy as np
    df1 = pd.read_csv('...l//airline_passengers.csv',index_col='Month',parse_dates=True)
    df1.index.freq = 'MS'
    #STLForecast

    from statsmodels.tsa.forecasting.stl import STLForecast
    from statsmodels.tsa.exponential_smoothing.ets import ETSModel

    stlf1 = STLForecast(df1, ETSModel)
    stlf_res=stlf1.fit()
    forecast1 = stlf_res.forecast(12) ----> If i Do forecast its working
    forecast1

    stlf2 = STLForecast(df1, ETSModel)
    stlf_res2=stlf2.fit()
    forecast2 = stlf_res.get_prediction()
    forecast2 ----> Its giving error like below:
    Exception: Data must be 1-dimensional

    can somebody help?

  6. bashtage commented on Jun 25, 2021

    @bashtage
    Member

    Sounds pretty clear. df1 needs to be 1 dimensional. You can only process 1 series at a time.

  7. AndreasDL commented on Aug 30, 2021

    @AndreasDL

    I am getting the same error; the get_prediction method is the one causing the problem.
    The error has nothing to do with the df1, since it works perfectly fine before calling the .forecast(12)

    I gave it a start and enddate like and i also get the 1 dimensional error. Am i doing something wrong ? I am not even inputting arrays.

    stlf = _STLForecast(rows, ARIMA, model_kwargs=dict(order=(1,1,0), trend="t"))
    stlf_res = stlf.fit()

    Works
    forecast = stlf_res.forecast(12)

    doesn't work, tells me to get some 1 dimensional data
    forecast = stlf_res.get_prediction(
    start=datetime_start,
    end=datetime_end
    )

  8. bashtage commented on Aug 31, 2021

    @bashtage
    Member

    Can you post a complete demo of the issue? Are you using master or 0.12.2?

  9. added this to the 0.13 milestone on Sep 9, 2021
  10. kidusasfaw commented on Jun 20, 2022

    @kidusasfaw

    Hi @bashtage, it looks like the 1-dimenional error is still there in 0.13 for STLForecast. Any way to work around this issue to get prediction intervals from an STLForecast.fit().forecast()?

  11. bashtage commented on Jun 20, 2022

    @bashtage
    Member

    @kidusasfaw Can you post some code to show this issue?

  12. kidusasfaw commented on Jun 20, 2022

    @kidusasfaw

    Sorry @bashtage I just found out that the issue turns up when I use a one-column dataframe with a datetime index as opposed to a series with a datetime index. So this is not an issue anymore. Thank you for your response :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions