Search code examples
pythonpandasstatisticsstatsmodelsarima

Statsmodels ARIMA, Value warning, date index and associated frequency information


I am currently building ARIMA models in python and has come across this error which I dont really understand when looking through the error code. I am curious if it affects the parameters in the model and would really appreciate if someone could advice on the issue, probably suggest a fix.

A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.

https://i.sstatic.net/sNZjd.png

The code in the error documentation in github goes as:

date_index = isinstance(index, (DatetimeIndex, PeriodIndex))

    if date_index and not has_freq:
        warnings.warn('A date index has been provided, but it has no'
                      ' associated frequency information and so will be'
                      ' ignored when e.g. forecasting.', ValueWarning)

Here is my dataframe. I have the date time set as my dataframe index.

https://i.sstatic.net/rlkd0.png

Just to be clear, the code is still executable and the result summary can be printed.


Solution

  • This warning shows up when your date index does not have a frequency associated with it.You have not provided a defined frequency (like quarterly, monthly, etc associated with the data/time index.

    What this warning means is that you cannot specify forecasting steps by dates, and the output of the forecast and get_forecast methods will not have associated dates. The reason is that without a given frequency, there is no way to determine what date each forecast should be assigned to. Try specifying a period like below:

    df.index = pd.DatetimeIndex(df.index).to_period('M')
    

    Read this page here for more details on the same. https://www.statsmodels.org/stable/examples/notebooks/generated/statespace_forecasting.html