statsmodels 的样本内预测中使用的公式是什么?

时间:2021-06-21 22:19:40

标签: statsmodels arima

我想知道在 statsmodels ARIMA 预测/预测中使用了什么公式。对于一个简单的 AR(1) 模型,我认为它是 y_t = a1 * y_t-1。但是,我无法重新创建预测或预测产生的结果。

这是我想要做的:

from statsmodels.tsa.arima.model import ARIMA
import numpy as np

def ar_series(n):
    # generate the series y_t = a1 y_t-1 + eps
    np.random.seed(1)
    y0 = np.random.rand()
    y = [y0]
    a1 = 0.7  # the AR coefficient
    for i in range(1, n):
        y.append(a1 * y[i - 1] + 0.3 * np.random.rand())
    return np.array(y)

series = ar_series(10)
model = ARIMA(series, order=(1, 0, 0))
fit = model.fit()
#print(fit.summary())
# const = 0.3441;   ar.L1 = 0.6518
print(fit.predict())
y_pred = [0.3441]

for i in range(1, 10):
    y_pred.append(  0.6518 * series[i-1])

y_pred = np.array(y_pred)
print(y_pred)

这两个系列不匹配,我不知道样本内预测是如何计算的?

1 个答案:

答案 0 :(得分:0)

在这里找到答案。我认为只有当过程均值为零时,我试图做的事情才有效。 https://faculty.washington.edu/ezivot/econ584/notes/forecast.pdf