auto.arima() equivalent for python(等价于 python 的 auto.arima())
问题描述
我正在尝试使用 ARMA ARIMA 模型预测每周销售额.我在 statsmodels 中找不到用于调整 order(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?
推荐答案
您可以实现多种方法:
ARIMAResults包括aic和bic.根据他们的定义,(请参阅 此处 和 这里),这些标准会惩罚模型中的参数数量.因此,您可以使用这些数字来比较模型.scipy 还有optimize.brute在指定的参数空间上进行网格搜索.所以像这样的工作流程应该可以工作:
ARIMAResultsincludeaicandbic. 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 hasoptimize.brutewhich 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.
Make sure you call brute with finish=None.
您可以从 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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:等价于 python 的 auto.arima()
基础教程推荐
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
