拟合模型后进行预测

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...