ValueWarning: No frequency information was provided, so inferred frequency MS will be used

那年仲夏 提交于 2019-12-22 05:03:16

问题


I try to fit Autoregression by sm.tsa.statespace.SARIMAX. But I meet a warning, then I want to set frequency information for this model. Who used to meet it, can you help me ?

fit1 = sm.tsa.statespace.SARIMAX(train.Demand, order=(1, 0, 0), 
                            enforce_stationarity=False,
                            enforce_invertibility=False).fit()
y_hat['AR'] = fit1.predict(start="1975-01-01", end="1975-12-01", dynamic=True)
plt.figure(figsize=(16,8))
plt.plot( train['Demand'], label='Train')
plt.plot(test['Demand'], label='Test')
plt.plot(y_hat_avg['AR'], label='AR')
plt.legend(loc='best')
plt.show()

C:\Users\thach.le\Anaconda3\lib\site-packages\statsmodels-0.8.0-py3.6-win- 
amd64.egg\statsmodels\tsa\base\tsa_model.py:165: ValueWarning: No frequency 
information was provided, so inferred frequency MS will be used.
% freq, ValueWarning)

Thanks


回答1:


If your data is really periodic and you don't have gaps in your time series, then pandas can infer the frequency.

If the inferred frequency looks correct to you, you can use it by follow the answer at Set pandas.tseries.index.DatetimeIndex.freq with inferred_freq

For example

train.index = pd.DatetimeIndex(train.index.values,
                               freq=train.index.inferred_freq)
fit1 = sm.tsa.statespace.SARIMAX(...)

But note that this can still give a DatetimeIndex whose frequency is None if your data is not truly periodic.

For example, if you have daily data and one day is missing, then the inferred_freq will be None and attempting to pass freq="D" will raise a ValueError exception. In this case, try building your DataFrame so that all dates are present and the values in the column(s) you're forecasting are None on those dates. Then you can use missing="drop" (or whatever) with your ARIMA model.



来源:https://stackoverflow.com/questions/49547245/valuewarning-no-frequency-information-was-provided-so-inferred-frequency-ms-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!