开始使用免费开始使用

预测的置信区间

您的预测对象 forecast_MET_t 不仅包含预测值,还包含称为置信区间的预测误差范围。由于任何预测都不可能完全准确,置信区间为我们的预测提供了上下浮动的空间。

预测值存储在对象 forecast_MET_t$mean 中。该区间的上下限也以类似方式存储。上置信区间的第二列是 95% 置信区间,可通过 forecast_MET_t$upper[,2] 访问。要获取下限,请将 upper 替换为 lower

本练习是课程的一部分

使用 R 预测产品需求

查看课程

练习说明

  • 将 95% 置信区间的上限和下限分别转换为 xts 对象 upperlower。您的日期索引存为 for_dates
  • 将它们添加到预测与验证数据集的图中。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Plot the validation data set
plot(MET_t_valid, main = 'Forecast Comparison', ylim = c(4000, 8500))

# Overlay the forecast of 2017
lines(for_MET_t_xts, col = "blue")

# Convert the limits to xts objects
lower <- xts(forecast_MET_t$___[,2], order.by = ___)
upper <- xts(___$___[,___], order.by = for_dates)

# Adding confidence intervals of forecast to plot
lines(lower, col = "blue", lty = "dashed")
lines(___, col = "blue", lty = "dashed")
编辑并运行代码