首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用python的ARIMA模型预测未知数据而不是训练数据

用python的ARIMA模型预测未知数据而不是训练数据
EN

Stack Overflow用户
提问于 2021-03-29 21:24:25
回答 1查看 414关注 0票数 2

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

代码语言:javascript
运行
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2021-03-30 23:23:22

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

代码语言:javascript
运行
复制
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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66855043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档