【问题标题】:What is the formula being used in the in-sample prediction of statsmodels?statsmodels 的样本内预测中使用的公式是什么?
【发布时间】:2021-06-21 22:19:40
【问题描述】:

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

这是我想要做的:

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)

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

【问题讨论】:

    标签: statsmodels arima


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-08
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 2018-01-17
      • 1970-01-01
      相关资源
      最近更新 更多