0

I'm trying to do a simple in-sample forecast utilizing statsmodels in Python, and the algorithm I'm using is ARIMA. I have a very simple linear dataset:

>>> data = pd.Series(data=range(0, 20))
>>> data
0      0
1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10    10
11    11
12    12
13    13
14    14
15    15
16    16
17    17
18    18
19    19

I ran ARIMA:

>>> from statsmodels.tsa.arima_model import ARIMA
>>> 
>>> #Function that calls ARIMA model to fit and forecast the data
... def StartARIMAForecasting(Actual, P, D, Q):
...     model = ARIMA(Actual, order=(P, D, Q))
...     model_fit = model.fit(disp=0)
...     prediction = model_fit.forecast()[0]
...     return prediction
... 
>>> predicted = StartARIMAForecasting(data, 5, 1, 0)

But I end up getting this error. I've checked the documentation and I also can't find where this error originates from.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in StartARIMAForecasting
  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/tsa/arima_model.py", line 1200, in fit
    callback, start_ar_lags, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/tsa/arima_model.py", line 986, in fit
    start_ar_lags)
  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/tsa/arima_model.py", line 577, in _fit_start_params
    start_params = self._fit_start_params_hr(order, start_ar_lags)
  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/tsa/arima_model.py", line 549, in _fit_start_params_hr
    arcoefs = yule_walker(endog, order=p)[0]
  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/regression/linear_model.py", line 1401, in yule_walker
    rho = np.linalg.solve(R, r[1:])
  File "<__array_function__ internals>", line 6, in solve
  File "/opt/anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py", line 403, in solve
    r = gufunc(a, b, signature=signature, extobj=extobj)
  File "/opt/anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py", line 97, in _raise_linalgerror_singular
    raise LinAlgError("Singular matrix")
numpy.linalg.LinAlgError: Singular matrix

I apologize for my haziness on linear algebra, but what is wrong with my input/why wouldn't it be generalizable for ARIMA?

  • Does this answer your question? [Why am I getting "LinAlgError: Singular matrix" from grangercausalitytests?](https://stackoverflow.com/questions/44305456/why-am-i-getting-linalgerror-singular-matrix-from-grangercausalitytests) – Trenton McKinney Jul 28 '20 at 18:36
  • https://stackoverflow.com/questions/28269123/singular-matrix-python – Trenton McKinney Jul 28 '20 at 18:38
  • Thanks for the link. So essentially my data would need noise because perfectly correlated data points are linear combinations of each other? How would this lead to a singular matrix in a univariate context? – Camille Dunning Jul 28 '20 at 19:24
  • That seems to be the case. I'm not an expert on this library, so a good place to start would be the [docs](https://www.statsmodels.org/stable/generated/statsmodels.tsa.arima_model.ARIMA.html), which also has a link to the [source code](https://www.statsmodels.org/stable/_modules/statsmodels/tsa/arima_model.html#ARIMA) for the function. – Trenton McKinney Jul 28 '20 at 19:27

0 Answers0