Skip to content

maxlag should be < nobs #3330

Closed
Closed

Description

@manishajohn

I have the sales input data for 2 years say for 2014-2015 from month 04(April)-12(Dec) and need to forecast the value for the year 2016.
In this case,i have only small amount of data say less than 50 rows.
For this i am getting the error "ValueError: maxlag should be < nobs" ,so i browsed and found that i need to set the lesser maxlag value,but have no clue where to set it.
Already tried setting it in fit(maxlag=intValue,ic='bic') but it is not getting assigned with the new value and again the same error.
Where i need to and how i should set it actually?
Please help.
Looking for your response.
This is the code i tried:

def test_final_output():
    df = pd.read_csv('../../data/salesoneproduct.csv', index_col=0)
    nobs=len(df)
    df.index.name=None
    df.reset_index(inplace=True)
    start = datetime.datetime.strptime("2014-04-01", "%Y-%m-%d")
    date_list = [start + relativedelta(months=x) for x in range(0,48)]
    df['index'] =date_list
    df.set_index(['index'], inplace=True)
    df.index.name=None
    df.columns= ['riders']
    df['riders'] = df.riders.apply(lambda x: int(x)*100)
    mod = sm.tsa.statespace.SARIMAX(df.riders, trend='n', order=(0,1,0), seasonal_order=(1,1,1,12)
    results = mod.fit(ic='bic',maxlag=10)
    start = datetime.datetime.strptime("2019-04-01", "%Y-%m-%d")
    date_list = [start + relativedelta(months=x) for x in range(0,12)]
    future = pd.DataFrame(index=date_list, columns= df.columns)
    df = pd.concat([df, future])
    df['forecast'] = results.predict(start = 48, end = 59, dynamic= True)
    df[['riders', 'forecast']].ix[-24:].plot(figsize=(12, 8))
    print (df.forecast/100)

Activity

  1. ChadFulton commented on Dec 26, 2016

    @ChadFulton
    Member

    Thanks for the bug report! In this case, the bug is that we don't give a more informative error message.

    The problem here is that starting parameters for the numerical optimization procedure can't be computed for the model you're trying to fit because you have too few observations to perform conditional least squares (which is how we get starting parameters). In this case, there's nothing to be done but specify starting parameters yourself, for example you could do:

    start_params = [0, 0, 1.]
    results = mod.fit(start_params)

    I should also note that the maxlag and ic parameters have no effect for the SARIMAX model.

    As a final note - the model you're specifying is probably not going to give great results even if you get it to perform the fitting, since you have so little data. I think you have 21 observations, and your seasonal order is 12. That means you don't even have two complete seasons worth of data.

  2. josef-pkt commented on Jan 1, 2017

    @josef-pkt
    Member

    I reformatted the code in the description.
    FAQ label because I don't know if there is anything to do.

  3. denizn commented on Apr 5, 2018

    @denizn

    Hello Chad,

    Why did you state that a model with 1-2 years of observations would not be performing great results?

    I am trying to forecast retail sales/demand with SARIMAX using statsmodels. I received also the same error. How do I know which parameters should I be using?

    Thank you,
    Deniz.

  4. denizn commented on May 1, 2018

    @denizn

    Is exactly two years of data usable for SARIMAX? If I have two complete seasons would I be able to proceed?

  5. ChadFulton commented on May 2, 2018

    @ChadFulton
    Member

    Why did you state that a model with 1-2 years of observations would not be performing great results?

    Just because you wouldn't have very many full seasons and you'd risk overfitting the model to a small number of datapoints. It's similar to why a regression with only a couple of observations may not provide very useful inference.

    Is exactly two years of data usable for SARIMAX? If I have two complete seasons would I be able to proceed?

    If that's all the data you have, then that's certainly better than nothing.

    However, depending on your model, you may need more than two complete seasons to estimate the starting parameters. See my comments here: #4465 (comment)

  6. Chroa3 commented on Nov 15, 2018

    @Chroa3

    image
    Some help to fix up these errors please?

    Thanks in advance.

  7. ChadFulton commented on Nov 15, 2018

    @ChadFulton
    Member
  8. Chroa3 commented on Nov 15, 2018

    @Chroa3

    I´ll do that then, thanks a lot for your quick response Chad!

  9. sbnbari commented on Dec 18, 2018

    @sbnbari

    Hi Chad
    i'm trying the dickey fuller test on yearly data and want to make it stationary but im unable to do it. i have applied that test on monthly and daily but getting an error while applying the ADF on yearly data which i'm going to use for my ARIMA model. your help will be much appreciated.
    capture 3 error

  10. ChadFulton commented on Dec 19, 2018

    @ChadFulton
    Member

    Hi @sbnbari can you make a new issue, since your question is about ADF and this issue is about SARIMAX.

    Please also copy and paste the error you're receiving (from your screenshot, I can only see the top of the ValueError, but not the whole traceback), and also let us know the output of:

    python -c "import statsmodels; print(statsmodels.__version__)"

    Thanks!

  11. sbnbari commented on Dec 19, 2018

    @sbnbari

    thanks
    check this link please
    #5432

  12. added 2 commits that reference this issue on May 11, 2019
    6b996a5
    b1cf266
  13. AtifKhan777 commented on Nov 27, 2019

    @AtifKhan777

    @ChadFulton I have the sales input data for 3 years say for 2015-2017 and need to forecast the value for the year 2018.
    In this case,i have only data say less than 210
    error
    rows.
    For this i am getting the error "ValueError: maxlag should be < nobs" ,so i browsed and found that i need to set the lesser maxlag value,but have no clue where to set it.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions