【问题标题】:Conditional Forcasting with VAR model in python在 python 中使用 VAR 模型进行条件预测
【发布时间】:2017-12-19 20:35:38
【问题描述】:

我正在使用 VAR 模型来预测滞后 2 的多元时间序列。我有三个特征,并希望向前预测几个时间戳。我实际上并没有预测所有三个特征,而是知道其中两个特征的值,并且只想预测一个特征。

如果我想一次预测所有三个特征 5 个时间戳,我可以这样做(这是一个玩具示例):

import pandas as pd
from statsmodels.tsa.api import VAR    
data=pd.DataFrame({'Date':['1959-06-01','1959-06-02','1959-06-03','1959-06-04']\
                   ,'a':[1,2,3,5],'b':[2,3,5,8],'c':[3,4,7,11]})
data.set_index('Date', inplace=True)
model = VAR(data)
results = model.fit(2)
results.forecast(data.values[-2:], 5)

注意data

            a  b   c
Date                
1959-06-01  1  2   3
1959-06-02  2  3   4
1959-06-03  3  5   7
1959-06-04  5  8  11

预测给了我

array([[   8.01388889,   12.90277778,   17.79166667],
       [  12.93113426,   20.67650463,   28.421875  ],
       [  20.73343461,   33.12405961,   45.51468461],
       [  33.22366195,   52.98948789,   72.75531383],
       [  53.15895736,   84.72805652,  116.29715569]])

假设我知道 a 的下 5 个值实际上应该是 8,13,21,34,55b 的下 5 个值应该是 13,21,34,55,89。有没有办法将其合并到 statsmodels.tsa(或任何其他 python 包)中的模型中以仅预测 c 的 5 个值?我知道R 有这样一个选项,通过将“硬”条件合并到cpredict.VAR 中,但我想知道这是否也可以在 python 中完成。

以上是一个玩具示例。实际上,我有几十个特征,但我仍然知道所有这些特征,并且只想使用 VAR 模型预测其中一个。

【问题讨论】:

  • 目前不直接支持。 (没有 statsmodels 贡献者看过这个案例,AFAIK)。其中R包是cpredict.VAR。
  • @user333700 感谢您告诉我。我提到的 R 包是 researchgate.net/… 的“条件预测”(第 403 页)部分中描述的包。
  • S+FinMetrics 是一个商业 S-plus 软件包,AFAICS。我不知道在 statsmodels VAR 或 statespace 版本 VARMAX 之上实现它会有多困难。
  • 这不是有点类似于脉冲响应分析吗? Python statsmodels 有处理它的模块(但我自己没有使用它们)。

标签: python r statistics time-series statsmodels


【解决方案1】:

我在解决这个问题时遇到了类似的问题。这是完成您所要求的临时方法。

prediction = model_fit.forecast(model_fit.y, steps=len(test))
predictions = prediction[:,0]

` 其中 prediction[:,0] 中的 0 是指包含所需预测值的列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 2018-11-11
    • 2016-03-08
    • 2017-12-12
    • 1970-01-01
    • 2019-06-14
    • 2016-02-16
    • 1970-01-01
    相关资源
    最近更新 更多