擬合模型後進行預測

R 中的監督式學習:回歸

Nina Zumel and John Mount

Win-Vector LLC

從訓練資料產生預測

cricket$prediction <- predict(cmodel)
  • predict() 預設會回傳訓練資料的預測值。
R 中的監督式學習:回歸

檢視預測結果

ggplot(cricket, aes(x = prediction, y = temperature)) + 
     geom_point() +
     geom_abline(color = "darkblue") + 
     ggtitle("temperature vs. linear model prediction")

R 中的監督式學習:回歸

對新資料進行預測

newchirps <- data.frame(chirps_per_sec = 16.5)
newchirps$prediction <- predict(cmodel, newdata = newchirps)
newchirps
   chirps_per_sec     pred
 1           16.5 79.53537

R 中的監督式學習:回歸

一起來練習吧!

R 中的監督式學習:回歸

Preparing Video For Download...