开始使用免费开始使用

使用 glm() 进行预测

数据科学家常用模型来预测未来情形。GLM 就是这样的工具之一,在用于此类任务时,有时也称为"监督学习"(supervised learning)。

在本练习中,您将使用之前拟合的 Poisson 回归和 new_dat 数据集,预测北美夏季 6 月(6)、7 月(7)和 8 月(8)每天平民火灾受伤人数的期望值。

回顾一下,Poisson 回归的斜率和截距估计是在自然对数刻度上,取指数后更便于理解。您可以在 predict 函数中指定 type = "response" 来完成这一点。

本练习是课程的一部分

R 中的广义线性模型

查看课程

练习说明

  • 打印 new_dat,查看新的预测情境。
  • 使用已拟合的 Poisson 回归 poisson_out 作为对象,并将 new_dat 作为 predict() 的新数据。务必通过设置 type = "response" 来对输出取指数。将结果保存为 pred_out
  • 打印 pred_out

交互式实操练习

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

# print the new input months
print(___)

# use the model to predict with new data 
___ <- predict(object = ___, newdata = ___, type = "response")

# print the predictions
print(___)
编辑并运行代码