简体   繁体   English

使用 Statsmodels 进行 SARIMAX 预测有问题吗?

[英]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)如下:

  • 138068 138068
  • 145810 145810
  • 149686 149686
  • 147245 147245
  • 140676 140676

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.

相关问题 在 statsmodels 中使用 SARIMAX 的 LU 分解错误 - LU decomposition error using SARIMAX in statsmodels 无法理解和使用Statsmodels的SARIMAX`conf_int()`输出 - Trouble understanding and using Statsmodels' SARIMAX `conf_int()` output 在 Statsmodels -python 中使用 SARIMAX 预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using SARIMAX in Statsmodels -python 使用 statsmodels SARIMAX 手动创建平均响应的置信区间 - Manually creating confidence intervals for the mean response using statsmodels SARIMAX Statsmodels API:缺少SARIMAX函数 - Statsmodels API: SARIMAX function missing ARIMA(python statsmodels)的预测 - Predictions with ARIMA (python statsmodels) Python Statsmodels:将SARIMAX与外生回归变量一起使用以获取预测的均值和置信区间 - Python Statsmodels: Using SARIMAX with exogenous regressors to get predicted mean and confidence intervals 使用Seaborn和Statsmodels在一个图中显示数据和模型预测 - Showing data and model predictions in one plot using Seaborn and Statsmodels 如何在 python statsmodels 中使用 X-13-ARIMA 进行预测 - How to get predictions using X-13-ARIMA in python statsmodels Spark 和 Python:并行化/映射统计模型的策略 sarimax - Spark & Python: strategy for parallelize/map statsmodels sarimax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM