Fit an xgboost bike rental model and predict
In this exercise, you will fit a gradient boosting model using xgboost() to predict the number of bikes rented in an hour as a function of the weather and the type and time of day. You will train the model on data from the month of July and predict on data for the month of August.
The data frames bikesJuly, bikesJuly.treat, bikesAugust, and bikesAugust.treat have also been pre-loaded. Remember the vtreat-ed data no longer has the outcome column, so you must get it from the original data (the cnt column).
For convenience, the number of trees to use, ntrees from the previous exercise is available to use.
The arguments to xgboost() (docs) are similar to those of xgb.cv().
Este exercício faz parte do curso
Supervised Learning in R: Regression
Instruções do exercício
- Fill in the blanks to run xgboost()on the July data.- Use as.matrix()to convert the vtreated data frame to a matrix.
- The objective should be "reg:squarederror".
- Use ntreesrounds.
- Set etato0.75,max_depthto5, andverbosetoFALSE(silent).
 
- Use 
- Now call predict()onbikesAugust.treatto predict the number of bikes rented in August.- Use as.matrix()to convert thevtreat-ed test data into a matrix.
- Add the predictions tobikesAugustas the columnpred.
 
- Use 
- Fill in the blanks to plot actual bike rental counts versus the predictions (predictions on the x-axis).- Do you see a possible problem with the predictions?
 
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Run xgboost
bike_model_xgb <- xgboost(data = ___, # training data as matrix
                   label = ___,  # column of outcomes
                   nrounds = ___,       # number of trees to build
                   objective = ___, # objective
                   eta = ___,
                   max_depth = ___,
                   verbose = FALSE  # silent
)
# Make predictions
bikesAugust$pred <- ___(___, ___(___))
# Plot predictions (on x axis) vs actual bike rental count
ggplot(bikesAugust, aes(x = ___, y = ___)) + 
  geom_point() + 
  geom_abline()