Python 中 Statsmodels ARIMA 的多个输入 [英] Multiple inputs into Statsmodels ARIMA in Python

查看:27
本文介绍了Python 中 Statsmodels ARIMA 的多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试拟合具有多个输入的 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.

推荐答案

建模 使用 ARIMA.

因此,您的代码的问题在于 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屋!

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