Learn R Programming

adabag (version 2.1)

bagging: Applies the Bagging algorithm to a data set

Description

Fits the Bagging algorithm proposed by Breiman in 1996 using classification trees as single classifiers.

Usage

bagging(formula, data, mfinal = 100, control)

Arguments

formula
a formula, as in the lm function.
data
a data frame in which to interpret the variables named in the formula
mfinal
an integer, the number of iterations for which boosting is run or the number of trees to use. Defaults to mfinal=100 iterations.
control
options that control details of the rpart algorithm. See rpart.control for more details.

Value

  • An object of class bagging, which is a list with the following components:
  • formulathe formula used.
  • treesthe trees grown along the iterations.
  • votesa matrix describing, for each observation, the number of trees that assigned it to each class.
  • classthe class predicted by the ensemble classifier.
  • samplesthe bootstrap samples used along the iterations.
  • importancereturns the relative importance of each variable in the classification task. This measure is the number of times each variable is selected to split.

Details

Unlike boosting, individual classifiers are independent among them in bagging

References

Alfaro, E., Gamez, M. and Garcia, N. (2007): ``Multiclass corporate failure prediction by Adaboost.M1''. International Advances in Economic Research, Vol 13, 3, pp. 301--312. Breiman, L. (1996): "Bagging predictors". Machine Learning, Vol 24, 2, pp.123--140. Breiman, L. (1998). "Arcing classifiers". The Annals of Statistics, Vol 26, 3, pp. 801--849.

See Also

predict.bagging, bagging.cv

Examples

Run this code
## rpart library should be loaded
library(rpart)
data(iris)
names(iris)<-c("LS","AS","LP","AP","Especies")
lirios.bagging <- bagging(Especies~LS +AS +LP+ AP, data=iris, mfinal=10)

## rpart and mlbench libraries should be loaded
library(rpart)
library(mlbench)
data(BreastCancer)
l <- length(BreastCancer[,1])
sub <- sample(1:l,2*l/3)
BC.bagging <- bagging(Class ~.,data=BreastCancer[,-1],mfinal=25, control=rpart.control(maxdepth=3))
BC.bagging.pred <- predict.bagging(BC.bagging,newdata=BreastCancer[-sub,-1])
BC.bagging.pred$confusion
BC.bagging.pred$error

# Data Vehicle (four classes)
library(rpart)
library(mlbench)
data(Vehicle)
l <- length(Vehicle[,1])
sub <- sample(1:l,2*l/3)
Vehicle.bagging <- bagging(Class ~.,data=Vehicle[sub, ],mfinal=50, control=rpart.control(maxdepth=5))
Vehicle.bagging.pred <- predict.bagging(Vehicle.bagging,newdata=Vehicle[-sub, ])
Vehicle.bagging.pred$confusion
Vehicle.bagging.pred$error

Run the code above in your browser using DataLab