Get startedGet started for free

Predict bike rentals with the random forest model

In this exercise, you will use the model that you fit in the previous exercise to predict bike rentals for the month of August.

The predict() (docs) function for a ranger model produces a list. One of the elements of this list is predictions, a vector of predicted values. You can access predictions with the $ notation for accessing named elements of a list:

predict(model, data)$predictions

The model bike_model_rf and the dataset bikesAugust (for evaluation) have been pre-loaded.

This exercise is part of the course

Supervised Learning in R: Regression

View Course

Exercise instructions

  • Call predict() on bikesAugust to predict the number of bikes rented in August (cnt). Add the predictions to bikesAugust as the column pred.
  • Fill in the blanks to calculate the root mean squared error of the predictions.
    • The poisson model you built for this data gave an RMSE of about 112.6. How does this model compare?
  • Fill in the blanks to plot actual bike rental counts (cnt) versus the predictions (pred on x-axis).

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# bikesAugust is available
str(bikesAugust)

# bike_model_rf is available
bike_model_rf

# Make predictions on the August data
bikesAugust$pred <- ___(___, ___)$___

# Calculate the RMSE of the predictions
bikesAugust %>% 
  mutate(residual = ___)  %>% # calculate the residual
  summarize(rmse  = ___)      # calculate rmse

# Plot actual outcome vs predictions (predictions on x-axis)
ggplot(bikesAugust, aes(x = ___, y = ___)) + 
  geom_point() + 
  geom_abline()
Edit and Run Code