简体   繁体   English

传递exog值时,ARMAX模型预测会导致“ ValueError:矩阵未对齐”

[英]ARMAX model forecasting leads to “ValueError: matrices are not aligned” when passing exog values

I'm struggling with forecasting out of sample values with an ARMAX model. 我正在努力使用ARMAX模型预测样本值。

Fitting the model works fine. 拟合模型效果很好。

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)

leads to "ValueError: matrices are not aligned". 导致“ ValueError:矩阵未对齐”。

My first idea was, that the length of *media_out* does not fit. 我的第一个想法是* media_out *的长度不合适。 I checked it several times and tried out to pass other series as exog. 我检查了几次,并尝试通过其他系列作为exog。 Length of exog is the same as number of steps. exog的长度与步骤数相同。 I tried out a time series and also only *media_out.values*. 我尝试了一个时间序列,也只尝试了* media_out.values *。

Checked the documentation: 检查了文档:

"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."

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. 另外,我在网上寻找解决方案时发现了这个ipython笔记本http://nbviewer.ipython.org/cb6e9b476a41586958b5 On In [53]: you can see a similar error. 在[53]中:您可以看到类似的错误。 The author's comment suggests a general problem with out-of-sample prediction, am I right? 作者的评论暗示了样本外预测的一个普遍问题,对吗?

I'm running python 2.7.3, pandas 0.12.0-1 and statsmodels 0.5.0-1. 我正在运行python 2.7.3,pandas 0.12.0-1和statsmodels 0.5.0-1。

Ah, I see the issue. 嗯,我明白了。 You need to pass in past data too. 您还需要传递过去的数据。 Eg, 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. 例如,如果要预测ARMAX(2,q)模型的12个步骤,则exog的长度应为14。您需要两个额外的滞后才能预测1个步骤。 So if you ensure exog is 2d, this should work as expected. 因此,如果您确保exog为2d,这应该可以正常工作。

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. 现在,我将在文档中将其记录下来。

[ 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. 使用ARMA预测https://github.com/statsmodels/statsmodels/pull/1124时,您不再需要提供任何样本变量 ] ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:Endog和Exog的索引未对齐 - ValueError: The indices for endog and exog are not aligned ValueError:矩阵未对齐 - ValueError: matrices are not aligned 如何修复错误:ValueError: endog 和 exog 矩阵的大小不同 - How to fix the error: ValueError: endog and exog matrices are different sizes ValueError:矩阵未对齐,且矩阵形状正确 - ValueError: matrices are not aligned, with correct shape of matrices ValueError:endog 和 exog 矩阵的大小不同 - 如何仅删除特定列中的数据? - ValueError: endog and exog matrices are different sizes - how to drop data in specific columns only? LinearRegression Predict- ValueError:矩阵未对齐 - LinearRegression Predict- ValueError: matrices are not aligned ValueError:矩阵未针对复制错误和x [:]对齐 - ValueError: matrices are not aligned for copy error and x[:] ValueError:形状(1,1000)和(1,1000)不对齐:1000(dim 1)!= 1(dim 0)当numpy.dot()具有两个矩阵时 - ValueError: shapes (1,1000) and (1,1000) not aligned: 1000 (dim 1) != 1 (dim 0) When numpy.dot() with two matrices ValueError:Endog 和 Exog 大小不同 - ValueError: Endog and Exog are in different size 如何将Python statsmodels用作R的lm.fit? 得到“ ValueError:endog和exog的索引未对齐” - How can I use Python statsmodels as R's lm.fit? Getting “ValueError: The indices for endog and exog are not aligned”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM