# Example to illustrate boosting # T. Yee, 202305. data(Boston, package = "MASS") library("rpart") # Set things up n <- nrow(Boston) Ngrid <- 500 range.crim <- with(Boston, range(crim)) # min and max Newdata <- data.frame(crim = exp(seq(log(range.crim[1]), log(range.crim[2]), length = Ngrid))) # Scatterplot plot(medv ~ log(crim), Boston, las = 1, col = "blue", main = "Boosting regression tree example") # Now do some boosting library("gbm") set.seed(1) boost.boston <- gbm(medv ~ log(crim), data = Boston, distribution = "gaussian", n.trees = 747, # Can control the complexity here interaction.depth = 1) # Stump Pred <- predict(boost.boston, Newdata) # Add the boosted tree to the plot lines(Pred ~ log(crim), Newdata, col = 1, lwd = 5)