使用python的ARIMA模型进行预测,使用看不见的数据而不是训练数据



我将ARIMA模型拟合到时间序列中。现在,我想使用该模型来预测接下来的步骤,例如,给定某个输入序列的1个测试。通常我发现使用了fit.forecast(((如下所示(,但这个预测适用于它用于拟合的序列,而我想获得同一序列不同部分的预测。

from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(series, order=(2,0,0))
fit = model.fit()
forecast = fit.forecast()[0] # this forecast the next value given the last 2 step in 'series'

有多种方法可以使用模型和拟合参数从(a(原始数据集中的不同起点、(b(添加新观测值后或(c(完全不同的数据集生成预测。

from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(series, order=(2,0,0))
fit = model.fit()
# Forecast five steps from the end of `series`
fit.forecast(5)
# Forecast five steps starting after the tenth observation in `series`
# Note that the `dynamic=True` argument specifies that it only uses the
# actual data through the tenth observation to produce each of the
# five forecasts
fit.predict(10, 14, dynamic=True)
# Add new observations (`new_obs`) to the end of the dataset
# *without refitting the parameters* and then forecast
# five steps from the end of the new observations
fit_newobs = fit.append(new_obs, refit=False)
fit_newobs.forecast(5)
# Apply the model and the fitted parameters to an
# entirely different dataset (`series2`) and then forecast
# five steps from the end of that new dataset
fit_newdata = fit.apply(series2)
fit_newdata.forecast(5)

您可能会发现以下笔记本很有用:https://www.statsmodels.org/devel/examples/notebooks/generated/statespace_forecasting.html

最新更新