适用于python的auto.arima() [英] auto.arima() equivalent for python

查看:786
本文介绍了适用于python的auto.arima()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ARMA ARIMA模型预测每周销售量.我在statsmodels中找不到用于调整顺序(p,d,q)的函数.当前,R具有函数forecast::auto.arima(),该函数将调整(p,d,q)参数.

I am trying to predict weekly sales using ARMA ARIMA models. I could not find a function for tuning the order(p,d,q) in statsmodels. Currently R has a function forecast::auto.arima() which will tune the (p,d,q) parameters.

如何为模型选择正确的顺序? python中有为此目的提供的任何库吗?

How do I go about choosing the right order for my model? Are there any libraries available in python for this purpose?

推荐答案

您可以实现多种方法:

  1. ARIMAResults 包括aicbic.根据其定义,(请参见此处 optimize.brute 会在指定的参数空间上进行网格搜索.因此,这样的工作流程应该可以工作:

  1. ARIMAResults include aic and bic. By their definition, (see here and here), these criteria penalize for the number of parameters in the model. So you may use these numbers to compare the models. Also scipy has optimize.brute which does grid search on the specified parameters space. So a workflow like this should work:

def objfunc(order, exog, endog):
    from statsmodels.tsa.arima_model import ARIMA
    fit = ARIMA(endog, order, exog).fit()
    return fit.aic()

from scipy.optimize import brute
grid = (slice(1, 3, 1), slice(1, 3, 1), slice(1, 3, 1))
brute(objfunc, grid, args=(exog, endog), finish=None)

确保使用finish=None调用brute.

您可以从ARIMAResults获取pvalues.因此,一种易于执行的步进算法可以在整个维度上增加模型的度数,从而为添加的参数获得最低的p值.

You may obtain pvalues from ARIMAResults. So a sort of step-forward algorithm is easy to implement where the degree of the model is increased across the dimension which obtains lowest p-value for the added parameter.

使用 ARIMAResults.predict 交叉验证替代模型.最好的方法是将时间序列的尾部(例如最新数据的5%)保留在样本之外,并使用这些点来获取拟合模型的测试误差.

这篇关于适用于python的auto.arima()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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