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()
基础教程推荐
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
