[英]Is there a Problem with SARIMAX Predictions Using Statsmodels?
I'm building a time series model in Python using the Statsmodels library.我正在使用 Statsmodels 库在 Python 中构建时间序列模型。
I seem to be getting erroneous results when I use the predict method on a SARIMAX model with exogenous regressors.当我在具有外生回归量的 SARIMAX 模型上使用预测方法时,我似乎得到了错误的结果。 (The predict method seems to work fine in the no external regressors case.)
(在没有外部回归量的情况下,预测方法似乎工作正常。)
Here is a full reproduction of the problem:这是问题的完整再现:
import numpy as np
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX, SARIMAXResults
history = np.array([95818, 126537, 102856, 161188, 150539, 165138, 146603, 154334,
150875, 134049, 137822, 126369, 124641, 111735, 126453])
history_exog = np.array([11.9835, 12.1981, 11.7108, 10.8174, 9.48247, 8.49162, 8.15208, 7.81663,
8.22422, 9.9492, 10.8724, 10.9911, 9.55874, 6.67079, 3.13028])
future_exog = np.array([0.279386, -1.72252, -2.87699, -2.64897, -1.51616])
model = SARIMAX(history,
order=(1,0,0),
seasonal_order=(0,0,0,52),
exog = history_exog,
enforce_stationarity=False,
enforce_invertibility=False)
model_fit = model.fit(method = 'cg')
yhat = model_fit.predict(start = len(history),
end = len(history) + 5 - 1,
exog = future_exog)
model_fit.summary()
The five steps ahead prediction I get (yhat) are as follows:我得到的五步预测(yhat)如下:
You can see the problem in the very first prediction.您可以在第一个预测中看到问题。 Given the model parameters, I would have thought that the prediction would be:
鉴于模型参数,我会认为预测将是:
yhat(t+1) = (126453 x 0.9898) + (-4579.3944 x 0.279386) = 123883.76
yhat(t+1) = (126453 x 0.9898) + (-4579.3944 x 0.279386) = 123883.76
The prediction I get is 138068.我得到的预测是 138068。
Where am I going wrong here?我哪里出错了? Or could this be a bug?
或者这可能是一个错误?
The SARIMAX model is of the form "regression with SARIMA errors". SARIMAX 模型的形式为“带有 SARIMA 错误的回归”。 For example, for an ARX(1) model, this is:
例如,对于 ARX(1) 模型,这是:
y(t) = beta' x(t) + e(t)
e(t) = phi e(t-1) + z(t)
while your forecasting equation would be accurate for a model of the form:而您的预测方程对于以下形式的模型是准确的:
y(t) = beta' x(t) + phi y(t-1) + z(t)
If you are interested in an AR(p) model (ie does not include any MA terms), then you can use sm.tsa.AutoReg
, which is of that form.如果您对 AR(p) 模型感兴趣(即不包括任何 MA 术语),那么您可以使用该形式的
sm.tsa.AutoReg
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.