bagging {adabag} | R Documentation |
Fits the Bagging algorithm proposed by Breiman in 1996 using classification trees as single classifiers.
bagging(formula, data, mfinal = 100, minsplit = 5, cp = 0.01, maxdepth = nlevels(vardep))
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. |
minsplit |
the minimum number of observations that must exist in a node, in order for a split to be attempted. |
cp |
complexity parameter. Any split that does not decrease the overall
lack of fit by a factor of cp is not attempted. |
maxdepth |
set the maximum depth of any node of the final tree, with the root node counted as depth 0 (past 30 rpart will give nonsense results on 32-bit machines). Defaults to the number of classes. |
Unlike boosting, individual classifiers are independent among them in bagging
An object of class bagging
, which is a list with the following components:
formula |
the formula used. |
trees |
the trees grown along the iterations. |
votes |
a matrix describing, for each observation, the number of trees that assigned it to each class. |
class |
the class predicted by the ensemble classifier. |
samples |
the bootstrap samples used along the iterations. |
importance |
returns the relative importance of each variable in the classification task. This measure is the number of times each variable is selected to split. |
Esteban Alfaro Cortes Esteban.Alfaro@uclm.es, Matias Gamez Martinez Matias.Gamez@uclm.es and Noelia Garcia Rubio Noelia.Garcia@uclm.es
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.
## 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, maxdepth=3) BC.bagging.pred <- predict.bagging(BC.bagging,newdata=BreastCancer[-sub,-1]) BC.bagging.pred[-1] # 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, maxdepth=5) Vehicle.bagging.pred <- predict.bagging(Vehicle.bagging,newdata=Vehicle[-sub, ]) Vehicle.bagging.pred[-1]