Get startedGet started for free

Predicting once you fit a model

1. Predicting once you fit a model

Now that you have learned to fit a linear regression model, let’s learn how to make predictions from the model. As with most model fitting algorithms in R, simply calling predict on the model returns the predictions for the data used to fit the model, or the training data. Here,

2. Predicting From the Training Data

we call predict on our cricket model and add a column of predictions to the training data frame. We can

3. Looking at the Predictions

compare the model’s predictions on the x axis to the actual temperatures in the data on the y axis. If the model predicted perfectly, all the points would lie on the blue line, x = y. This graph gives you a visual idea of how close the model’s predictions are to ground truth. In this course, we will use ggplot to create most of the plots.

4. Predicting on New Data

To apply the model to new data, use the argument newdata. Here, we have a new data frame of cricket observations called newchirps. We apply the model to newchirps and add the predictions as a new column to the data frame. The model predicts that a chirp rate of 16.5 chirps per second should correspond to a temperature of almost 80 degrees. Now let's practice

5. Let's practice!

fitting linear models and making predictions.