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

标签 python time-series arima

预测 ARIMA 模型参数的 p、d 和 q 值的正确方法是什么?

网格搜索如何帮助查找这些参数?

如何将非平稳数据转换为平稳数据以应用 ARIMA?

我已经提到了这个article

最佳答案

对于网格搜索方法,您可以使用分为两部分的方法:

  1. 评估 ARIMA 模型。
    • 将数据集分为训练集和测试集。
    • 遍历测试数据集中的时间步。
      • 训练 ARIMA 模型。
      • 进行一步预测。
      • 存储预测;获取并存储实际观察结果。
    • 计算预测与预期值的误差分数

这是代码:

# 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
  • 计算 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)) 
    

    有关更多详细信息,您可以在此链接中找到一个教程,其中开发了用于单步滚动预测的网格搜索 ARIMA 超参数,https://machinelearningmastery.com/grid-search-arima-hyperparameters-with-python/

    关于python - 如何在 python 中查找 ARIMA 模型的参数 [p, d, q] 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53677152/

    相关文章:

    python - 湿度时间序列预测

    python-3.x - 如何在使用 statsmodels 时修复此错误“ImportError : cannot import name 'factorial' "?

    python - 如何计算 'for' 循环中最后一项的平均值?

    Python Pandas 系列日期时间到纪元以来的秒数

    python - wx.Image 抛出 PyAssertionError

    R:将金融时间序列数据与 2 个大数据集进行模式匹配:

    python - Pandas For Loop 错误 - 嵌入了和/if 语句

    python - 如何匹配文本节点然后使用 XPath 跟随父节点

    postgresql - 可视化 SQL 数据库 (Postgres) 中的时间序列

    r - 从列表中提取 ARIMA 对象并将其存储在 R 的数据框中