简体   繁体   English

Python中Statsmodels ARIMA的多个输入

[英]Multiple inputs into Statsmodels ARIMA in Python

I am trying to fit a ARIMA model with multiple inputs. 我正在尝试使用多个输入来拟合ARIMA模型。 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

Obviously, there is something wrong (if p,d,q are all 0 then it is not working at all). 显然,出了点问题(如果p,d,q全部为0,则根本不起作用)。 Does anyone know what I am doing wrong? 有人知道我在做什么错吗?

Any advice that would point me to the right direction would be much appreciated. 我们会向我指出正确的方向的任何建议。

You need to have enough 'degrees of freedom' when modeling using ARIMA. 使用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. 因此,代码的问题在于np.dstack生成的数组形状为(1,3,2),这意味着它只有一个数据元素。 You need a minimum number of 6 data elements to be able to run the ARIMA model with p-value 5. 您至少需要6个数据元素才能运行p值为5的ARIMA模型。

Example on array operations. 数组操作示例 I used np.vstack to produce as many as rows as possible. 我使用np.vstack产生尽可能多的行。

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM