【问题标题】:Predict using fit pmdarima ARIMA model使用拟合 pmdarima ARIMA 模型进行预测
【发布时间】:2021-11-04 22:03:42
【问题描述】:

我可以使用 pmdarima 将 SARIMA 模型拟合到一些数据。

import pmdarima as pm
from pmdarima.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt

# Load/split
y = pm.datasets.load_wineind()
train, test = train_test_split(y, train_size=150)

# Fit
model = pm.auto_arima(train, seasonal=True, m=12)

我可以根据这些数据进行预测,我什至可以查看样本内预测,从中可以计算残差。

N = test.shape[0]  # predict N steps into the future
forecasts = model.predict(N)
in_sample_forecasts = model.predict_in_sample()

但 SARIMA 只是一个数学模型(据我所知)。所以我希望能够使用拟合的模型参数来完全预测其他一些系列。我可以这样做吗?

例如:

# Some other series entirely
some_other_series = train + np.random.randint(0, 5000, len(train))
# The following method does not exist but illustrates the desired functionality
forecasts = model.predict_for(some_other_series, N)

【问题讨论】:

    标签: python time-series statsmodels arima pmdarima


    【解决方案1】:

    我已经找到了解决方案。诀窍是运行另一个拟合,但让优化器在引擎盖下基本上对已经拟合的参数执行无操作。我发现method='nm'实际上服从了maxiter=0,而其他人则没有。下面是pmdarima 模型的代码,但同样的想法也适用于statsmodels 中的SARIMAX 模型。

    from copy import deepcopy
    # Some other series entirely
    some_other_series = train + np.random.randint(0, 5000, len(train))
    # Deep copy original model for later comparison
    new_model = deepcopy(model)
    new_model.method = 'nm'
    new_model.fit(some_other_series, maxiter=0, start_params=new_model.params())
    new_model.params()
    new_model.predict(12)
    # Note that the params have stayed the same and predictions are different
    model.params()
    model.predict(12)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      相关资源
      最近更新 更多