问题
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