Search code examples
pythonpandasstatsmodelsarimaforecast

Insufficient degrees of freedom to estimate


My degree of freedom is smaller than the number of rows in the dataset. Why do I have the error "Insufficient degrees of freedom to estimate". What can I do to resolve this error?

I have tried to reduce the value in differenced = difference(X,11), but it still shows the error.

dataset, validation = series[0:split_point], series[split_point:]
print('Dataset %d, Validation %d' % (len(dataset), len(validation)))
dataset.to_csv('dataset.csv')
validation.to_csv('validation.csv')
from pandas import Series
from statsmodels.tsa.arima_model import ARIMA
import numpy
# load dataset
series = Series.from_csv('dataset.csv', header=None)
series = series.iloc[1:]
series.head()
series.shape

from pandas import Series
from statsmodels.tsa.arima_model import ARIMA
import numpy
# create a differenced series
def difference(dataset, interval=1):
    diff = list()
    for i in range(interval+1, len(dataset)):
        value = int(dataset[i]) - int(dataset[i - interval])
        diff.append(value)
    return numpy.array(diff)

# load dataset
series = Series.from_csv('dataset.csv', header=None)
# seasonal difference
X = series.values
differenced = difference(X,11)
# fit model
model = ARIMA(differenced, order=(7,0,1))
model_fit = model.fit(disp=0)
# print summary of fit model
print(model_fit.summary())

series.head() result

The shape is (17,)


Solution

  • After differencing, you are left with 6 observations (17 - 11 = 6). That's not enough for an ARIMA(7, 0, 1).

    With that little data, you are unlikely to get good forecasting performance with any model, but if you must, then I would recommend something much simpler, like ARIMA(1, 0, 0) or an exponential smoothing model.