Exercise

Predict with the soybean model on test data

In this exercise, you will apply the soybean models from the previous exercise (model.lin and model.gam, already loaded) to new data: soybean_test.

Instructions

100 XP
  • Create a column soybean_test$pred.lin with predictions from the linear model model.lin.
  • Create a column soybean_test$pred.gam with predictions from the gam model model.gam.
    • For GAM models, the predict() method returns a matrix, so use as.numeric() to convert the matrix to a vector.
  • Fill in the blanks to gather() the prediction columns into a single value column pred with key column modeltype. Call the long data frame soybean_long.
  • Calculate and compare the RMSE of both models.
    • Which model does better?
  • Run the code to compare the predictions of each model against the actual average leaf weights.
    • A scatter plot of weight as a function of Time.
    • Point-and-line plots of the predictions (pred) as a function of Time.
    • Notice that the linear model sometimes predicts negative weights! Does the gam model?