使用 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(___)