简体   繁体   English

如何在python中找到ARIMA模型的参数[p,d,q]值?

[英]How to Find parameters [p, d, q] value for ARIMA model in python?

What is the correct way to predict p, d and q value for parameters for ARIMA model. 预测ARIMA模型参数的p,d和q值的正确方法是什么。

How Grid Search help to find these parameters? 网格搜索如何帮助您找到这些参数?

How to make Non stationary data to stationary to apply ARIMA? 如何使非固定数据变为固定数据以应用ARIMA?

I have already referred this article 我已经提到了这篇文章

For grid Searching Method you can use an approach which is broken down into two parts: 对于网格搜索方法,您可以使用分为两部分的方法:

  1. Evaluate an ARIMA model. 评估ARIMA模型。
    • Split the dataset into training and test sets. 将数据集分为训练集和测试集。
    • Walk the time steps in the test dataset. 在测试数据集中遍历时间步骤。
      • Train an ARIMA model. 训练ARIMA模型。
      • Make a one-step prediction. 做一个一步的预测。
      • Store prediction; 店铺预测; get and store actual observation. 获取并存储实际观察值。
    • Calculate error score for predictions compared to expected values 计算与预期值相比的预测错误分数

this the code: 这是代码:

# evaluate an ARIMA model for a given order (p,d,q)
def evaluate_arima_model(X, arima_order):
    # prepare training dataset
    train_size = int(len(X) * 0.66)
    train, test = X[0:train_size], X[train_size:]
    history = [x for x in train]
    # make predictions
    predictions = list()
    for t in range(len(test)):
        model = ARIMA(history, order=arima_order)
        model_fit = model.fit(disp=0)
        yhat = model_fit.forecast()[0]
        predictions.append(yhat)
        history.append(test[t])
    # calculate out of sample error
    error = mean_squared_error(test, predictions)
    return error
  1. Evaluate sets of ARIMA parameters this is the code: 评估ARIMA参数集,这是代码:
# evaluate combinations of p, d and q values for an ARIMA model
def evaluate_models(dataset, p_values, d_values, q_values):
    dataset = dataset.astype('float32')
    best_score, best_cfg = float("inf"), None
    for p in p_values:
        for d in d_values:
            for q in q_values:
                order = (p,d,q)
                try:
                    mse = evaluate_arima_model(dataset, order)
                    if mse < best_score:
                        best_score, best_cfg = mse, order
                    print('ARIMA%s MSE=%.3f' % (order,mse))
                except:
                    continue
    print('Best ARIMA%s MSE=%.3f' % (best_cfg, best_score)) 

For more details you can find in this link a tutorial, in which grid search ARIMA hyperparameters for a one-step rolling forecast is developped, https://machinelearningmastery.com/grid-search-arima-hyperparameters-with-python/ 有关更多详细信息,您可以在此链接中找到一个教程,其中开发了用于单步滚动预测的网格搜索ARIMA超参数, https ://machinelearningmastery.com/grid-search-arima-hyperparameters-with-python/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM