Skip to content

Instantly share code, notes, and snippets.

@necronet
Created August 7, 2019 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save necronet/c3c9aa8ce5c9c2a9a57a251f231233df to your computer and use it in GitHub Desktop.
Save necronet/c3c9aa8ce5c9c2a9a57a251f231233df to your computer and use it in GitHub Desktop.
Create multiple bagging trees and capture each RSME in order to graph the reduce in variance
errors <- vector()
for ( i in seq(from = 1, to = 50) ) {
print(paste('Bagging with',i,'trees'))
ames_bag_i <- bagging( formula = Sale_Price ~ ., data=ames_training, nbagg = i, control = rpart.control(minsplit = 2, cp = 0))
errors <- c(errors, ames_bag_i$err)
}
error_df <- as.data.frame(errors)
error_df$n_trees <- 1:nrow(error_df)
ggplot(data = error_df, aes(x = n_trees, y = errors)) + geom_line()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment