开始使用免费开始使用

Simple exponential smoothing

ses() 函数使用简单指数平滑(SES)来生成预测。参数通过最小二乘法估计。您只需指定时间序列和预测步数;默认的预测步数是 h = 10 年。

> args(ses)
function (y, h = 10, ...)

> fc <- ses(oildata, h = 5)
> summary(fc)

您还将首次使用 summary()fitted(),并配合 autolayer()。它与 autoplot() 类似,但不会创建新图,而是为现有图形添加一个"图层"。

这里,您将把这些函数应用到 marathon 数据上,它包含 1897-2016 年波士顿马拉松年度冠军成绩。数据已在您的工作区中可用。

本练习是课程的一部分

R 中的预测

查看课程

练习说明

  • 使用 ses() 函数预测未来 10 年的冠军成绩。
  • 使用 summary() 函数查看模型参数和其他信息。
  • 使用 autoplot() 函数绘制预测结果。
  • 使用 fitted()autolayer() 将训练数据的一步预测(即拟合值)添加到图中。

交互式实操练习

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

# Use ses() to forecast the next 10 years of winning times
fc <- ___(___, h = ___)

# Use summary() to see the model parameters
___

# Use autoplot() to plot the forecasts
___

# Add the one-step forecasts for the training data to the plot
autoplot(___) + autolayer(fitted(___))
编辑并运行代码