使用 MA 模型进行预测
与 AR 模型一样,您将使用 MA 模型结合 statsmodels 中的 plot_predict() 函数,对样本内和样本外数据进行预测。
对于参数 \(\small \theta=-0.9\) 的模拟序列 simulated_data_1,您将绘制样本内和样本外预测。与 AR(1) 模型的样本外预测相比,MA(1) 模型的一个显著不同在于:对超过一步期的未来进行预测时,预测值将退化为样本的均值。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 导入类
ARIMA,并导入函数plot_predict - 使用模拟数据
simulated_data_1和模型的 (p,d,q) 阶数(此处为 MA(1)),order=(0,0,1),创建一个名为mod的ARIMA实例 - 使用
.fit()方法拟合模型mod,并将结果保存为名为res的结果对象 - 绘制从索引 950 开始的样本内数据
- 使用
plot_predict()函数绘制样本外预测及其置信区间,从索引 950 开始,并在索引 1010 结束预测
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the ARIMA and plot_predict from statsmodels
from statsmodels.tsa.arima.model import ARIMA
from statsmodels.graphics.tsaplots import plot_predict
# Forecast the first MA(1) model
mod = ARIMA(___, order=___)
res = mod.fit()
# Plot the data and the forecast
fig, ax = plt.subplots()
simulated_data_1.loc[950:].plot(ax=ax)
plot_predict(res, start=___, end=___, ax=ax)
plt.show()