ARMAX模型预测导致"ValueError:矩阵未对齐".传递exog值时 [英] ARMAX model forecasting leads to "ValueError: matrices are not aligned" when passing exog values

查看:141
本文介绍了ARMAX模型预测导致"ValueError:矩阵未对齐".传递exog值时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用ARMAX模型对样本值进行预测.

I'm struggling with forecasting out of sample values with an ARMAX model.

拟合模型效果很好.

armax_mod31 = sm.tsa.ARMA(endog = sales, order = (3,1), exog = media).fit()
armax_mod31.fittedvalues

据我所知,没有外在价值的预测也可以正常工作.

Forecasting without exogenous values, as far as I have an according model, works fine as well.

arma_mod31 = sm.tsa.ARMA(sales, (3,1)).fit()
all_arma = arma_mod31.forecast(steps = 14, alpha = 0.05)
forecast_arma = Series(res_arma[0], index = pd.date_range(start = "2013-08-21", periods = 14)) 
ci_arma = DataFrame(res_arma[2], columns = ["lower", "upper"])

但是,一旦我要从样本值中进行预测,就会遇到问题.

However as soon as I want to predict out of sample values I run into problems.

all_armax = armax_mod31.forecast(steps = 14, alpha = 0.05, exog = media_out)

导致"ValueError:矩阵未对齐".

leads to "ValueError: matrices are not aligned".

我的第一个想法是* media_out *的 length 不合适. 我检查了几次,并尝试通过其他系列作为exog. exog的长度与步骤数相同.我尝试了一个时间序列 也只有* media_out.values *.

My first idea was, that the length of *media_out* does not fit. I checked it several times and tried out to pass other series as exog. Length of exog is the same as number of steps. I tried out a time series and also only *media_out.values*.

检查了文档:

"exog : array
If the model is an ARMAX, you must provide out of sample
values for the exogenous variables. This should not include
the constant."

据我了解,这就是我所做的.有什么想法我做错了吗? 另外,我发现了这个ipython笔记本 http://nbviewer.ipython.org/cb6e9b476a41586958b5 在网络上寻找解决方案. 在在[53]:中,您会看到类似的错误.作者的评论暗示了样本外预测的一个普遍问题,对吗?

As far as I understand this is what I do. Any ideas what I'm doing wrong? In addition I found this ipython notebook http://nbviewer.ipython.org/cb6e9b476a41586958b5 while looking for a solution on the web. On In [53]: you can see a similar error. The author's comment suggests a general problem with out-of-sample prediction, am I right?

我正在运行python 2.7.3,pandas 0.12.0-1和statsmodels 0.5.0-1.

I'm running python 2.7.3, pandas 0.12.0-1 and statsmodels 0.5.0-1.

推荐答案

嗯,我看到了问题.您还需要传递过去的数据.例如,如果您要预测ARMAX(2,q)模型的12个步骤,则exog的长度应为14.您需要两个额外的滞后才能预测1个步骤.因此,如果您确保exog为2d,这应该可以正常工作.

Ah, I see the issue. You need to pass in past data too. E.g., if you want to predict 12 steps of an ARMAX(2,q) model then exog should be of length 14. You need the two extra lags to be able to predict 1 step out. So if you ensure exog is 2d, this should work as expected.

无论如何我都看不到,但是如果您认为有什么需要改进的地方,请告诉我.现在,我将在文档中对其进行记录.

I can't see anyway around this, but let me know if you think there's something to improve here. For now I'll note it in the docs.

[编辑:我意识到这项要求很愚蠢.使用ARMA预测时,您不再需要提供任何示例变量. https://github.com/statsmodels/statsmodels/pull/1124.]

[Edit: I realized this requirement was stupid. You no longer have to supply any in-sample variables when using ARMA forecast https://github.com/statsmodels/statsmodels/pull/1124.]

这篇关于ARMAX模型预测导致"ValueError:矩阵未对齐".传递exog值时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆