我正在尝试使用 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
在指定的参数空间上进行网格搜索.所以像这样的工作流程应该可以工作:
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
.
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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!