我用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'发布于 2021-03-30 23:23:22
有多种方法可以使用模型和拟合参数从(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
https://stackoverflow.com/questions/66855043
复制相似问题