Python中Statsmodels ARIMA的多个输入 [英] Multiple inputs into Statsmodels ARIMA in Python
问题描述
我正在尝试使用具有多个输入的ARIMA模型.只要输入是单个数组,它就可以正常工作.
I am trying to fit a ARIMA model with multiple inputs. As long as the input was a single array it worked fine.
在此,建议将输入数组放入类似多维数组的结构中.所以我做到了:
Here, I was adviced to put input arrays into a multidimensional array-like structure. So I did:
import numpy as np
from statsmodels.tsa.arima_model import ARIMA
a = [1, 2, 3]
b = [4, 5, 6]
data = np.dstack([a, b])
for p in range(6):
for d in range(2):
for q in range(4):
order = (p,d,q)
try:
model = ARIMA(data, order=(p,d,q))
print("this works:{}, {}, {} ".format(p,d,q))
except:
pass
但是,此脚本的输出是这样的:
However, the output of this script was this:
this works:0, 0, 0
很明显,出了点问题(如果p,d,q都为0,则根本不起作用).有人知道我在做什么错吗?
Obviously, there is something wrong (if p,d,q are all 0 then it is not working at all). Does anyone know what I am doing wrong?
任何能给我指明正确方向的建议,将不胜感激.
Any advice that would point me to the right direction would be much appreciated.
推荐答案
当因此,您的代码存在的问题是np.dstack产生的数组形状为(1,3,2),这意味着它只有一个数据元素.您至少需要6个数据元素才能运行p值为5的ARIMA模型.
So, the issue with your code is that np.dstack produces the shape of the array as (1,3,2) which means it has only one data element. You need a minimum number of 6 data elements to be able to run the ARIMA model with p-value 5.
关于数组操作的
示例.我使用np.vstack产生尽可能多的行.
Example on array operations. I used np.vstack to produce as many as rows as possible.
请运行下面的代码片段,您将了解.
Please run the code snippet below and you will understand.
import numpy as np
from statsmodels.tsa.arima_model import ARIMA
a = [1, 2]
b = [3, 4]
c = [5, 6]
d = [7, 8]
data = np.vstack([a, b, c, d])
print(data.shape)
print(data)
for p in range(4):
for d in range(1):
for q in range(2):
order = (p,d,q)
try:
model = ARIMA(data, order=(p,d,q))
print("this works:{}, {}, {} ".format(p,d,q))
except:
print(order)
print('reached exception')
pass
这篇关于Python中Statsmodels ARIMA的多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!