Skip to content

arma_order_select_ic function throw "IndexError: index 0 is out of bounds for axis 0 with size 0" #4727

Closed

Description

@lbdhr

Hi, I got a problem when I run the code sm.tsa.arma_order_select_ic(ts,max_ar=6,max_ma=4,ic='aic')['aic_min_order'] # AIC with my dataset.

The problem showed below:

~/anaconda3/lib/python3.6/site-packages/statsmodels/tsa/stattools.py in arma_order_select_ic(y, max_ar, max_ma, ic, trend, model_kw, fit_kw)
   1149     for i, result in iteritems(res):
   1150         mins = np.where(result.min().min() == result)
-> 1151         min_res.update({i + '_min_order' : (mins[0][0], mins[1][0])})
   1152     res.update(min_res)
   1153 

IndexError: index 0 is out of bounds for axis 0 with size 0

However, I just cannot figure what is going on. And When I run the sample code, there is no problem. So what caused this problem? Is there something wrong with my dataset?

Activity

  1. lbdhr commented on Jun 7, 2018

    @lbdhr
    Author

    For ts, after run ts.tail(), the printed information is:

    index
    20174332     98.437500
    20174333    101.250000
    20174334     98.703125
    20174335     99.812500
    20174336    100.328125
    Name: pm25, dtype: float64
    
  2. josef-pkt commented on Jun 7, 2018

    @josef-pkt
    Member

    which version of pandas are you using?

    Can you use pdb to check what result and mins is?
    Result is a pandas.DataFrame, but I don't see why mins should be empty or not a tuple.

    i.e. somthing like

    result = pd.DataFrame(np.arange(12).reshape(4, 3))
    
    np.where(result.min().min() == result)
    Out[19]: (array([0], dtype=int64), array([0], dtype=int64))
    

    unless all results are nan

    result = pd.DataFrame(np.nan * np.arange(12).reshape(4, 3))
    np.where(result.min().min() == result)
    Out[21]: (array([], dtype=int64), array([], dtype=int64))
    
    np.where(result.min().min() == result)[0][0]
    Traceback (most recent call last):
    
      File "<ipython-input-23-83c722093758>", line 1, in <module>
        np.where(result.min().min() == result)[0][0]
    
    IndexError: index 0 is out of bounds for axis 0 with size 0
    
  3. lbdhr commented on Jun 7, 2018

    @lbdhr
    Author

    Hi, josef-pkt, thanks very much for your response. I just find the error is because the parameter that arma_order_select_ic need to be numpy.ndarray. However, the ts is Series type.

    So when I changed the code to sm.tsa.arma_order_select_ic(ts.values,max_ar=6,max_ma=4,ic='aic')['aic_min_order'] # AIC. Everything is fine. Thanks again~

  4. josef-pkt commented on Jun 7, 2018

    @josef-pkt
    Member

    I added bug label

    There is something strange
    y goes directly into ARIMA, so it should be fine.
    Most likely there is something in the results wrapper that changes things,
    in many other cases we get the _results below the results wrapper for further computation.
    However, AFAICS only the ic are taken from the results instance.

  5. added this to the 0.10 milestone on Jun 7, 2018
  6. josef-pkt commented on Jun 7, 2018

    @josef-pkt
    Member

    Whatever the reason, we don't need pandas in the order search, so we can just put an np.asarray into arma_order_select_ic

  7. added 4 commits that reference this issue on Aug 8, 2018
    a6cf099
    a732dd9
    74e13f0
    284fab9
  8. JavierCastilloGuillen commented on Apr 21, 2022

    @JavierCastilloGuillen

    Hi guys,

    Sorry to come back with this topic but I'm struggling a bit with the same scenario having the IndexError: index 0 is out of bounds for axis 0 with size 0 error.

    I'll paste the snippet of code here. Basically the data source comes from a pandas Series coming from a DataFrame which has been converted into np.array in order to avoid the error.

    Not sure why. I've tried to convert the data into arrays via few methods like the one in the example, the .values, np.asarray, etc and still giving the same error. Basically what I'm tring to get is the SBIC and AIC for the series as you can imagine.

    The version is statsmodels 0.13.2.

    If you can give a hand with this would be really appreciated. As said, not sure if it is me doing something wrong or is a general issue.

    Thanks in advance guys.

    Input:

    print(type(data['dhp']))
    y = np.array(data['dhp'])
    print(y.shape)
    print(type(y))
    print(data['dhp'].tail())
    sm.graphics.tsa.plot_acf(data['dhp'], lags=15)
    plt.show()
    
    res1 = smt.arma_order_select_ic(y , max_ar=5, max_ma=4, ic=['aic', 'bic'],fit_kw={'method':'css-mle','solver':'bfgs'})
    

    Output:

    PS C:\Users\javie\Desktop\Ejercicio Series Temporales ARIMA> & C:/Users/javie/miniconda3/python.exe "c:/Users/javie/Desktop/Ejercicio Series Temporales ARIMA/modelo.py"
    <class 'pandas.core.series.Series'>
    (326,)
    <class 'numpy.ndarray'>
    Month
    2017-11-01   -0.519801
    2017-12-01    0.556220
    2018-01-01    0.284286
    2018-02-01   -0.639190
    2018-03-01    0.581234
    Name: dhp, dtype: float64
    Traceback (most recent call last):
      File "c:\Users\javie\Desktop\Ejercicio Series Temporales ARIMA\modelo.py", line 76, in <module>
        res1 = smt.arma_order_select_ic(y , max_ar=5, max_ma=4, ic=['aic', 'bic'],fit_kw={'method':'css-mle','solver':'bfgs'})
      File "C:\Users\javie\miniconda3\lib\site-packages\statsmodels\tsa\stattools.py", line 1866, in arma_order_select_ic
        min_res.update({i + "_min_order": (mins[0][0], mins[1][0])})
    IndexError: index 0 is out of bounds for axis 0 with size 0
    
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