O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating regression trees using the ensemble method - Bagging and Boosting

Regression trees can also be built using the ensemble method that creates multiple models of the same type from different sub-samples of the same dataset.

Bootstrapped Aggregation (Bagging) is an ensemble method that combines together the predictions from separate tree models to provide superior results, and is also effective for high-variance methods such as decision trees.

Perform the following commands to apply bagging technique:

> install.packages("ipred")> library(ipred)> # using same BostonHousing.csv dataset used earlier> fit <- bagging(MEDV ~., data= bh[t.idx,], control=   rpart.control(minsplit=10))> prediction.t <- predict(fit, bh[t.idx,]) # on training ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required