Learn R Programming

adabag (version 2.1)

bagging.cv: Runs v-fold cross validation with Bagging

Description

The data are divided into v non-overlapping subsets of roughly equal size. Then, bagging is applied on (v-1) of the subsets. Finally, predictions are made for the left out subsets, and the process is repeated for each of the v subsets.

Usage

bagging.cv(formula, data, v = 10, mfinal = 100, control)

Arguments

formula
a formula, as in the lm function.
data
a data frame in which to interpret the variables named in formula
v
An integer, specifying the type of v-fold cross validation. Defaults to 10. If v is set as the number of observations, leave-one-out cross validation is carried out. Besides this, every value between two and the number of observations is
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.cv, which is a list with the following components:
  • classthe class predicted by the ensemble classifier.
  • confusionthe confusion matrix which compares the real class with the predicted one.
  • errorreturns the average error.

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

bagging, predict.bagging

Examples

Run this code
## rpart library should be loaded
library(rpart)
data(iris)
names(iris)<-c("LS","AS","LP","AP","Especies")
iris.baggingcv <- bagging.cv(Especies ~ ., v=10, data=iris, mfinal=10,control=rpart.control(maxdepth=3))

data(kyphosis)
kyphosis.baggingcv <- bagging.cv(Kyphosis ~ Age + Number + Start, 
	data=kyphosis, mfinal=15)

## rpart and mlbench libraries should be loaded
## Data Vehicle (four classes) 
library(rpart)
library(mlbench)
data(Vehicle)
Vehicle.bagging.cv <- bagging.cv(Class ~.,data=Vehicle,mfinal=25, control=rpart.control(maxdepth=5))
Vehicle.bagging.cv[-1]

Run the code above in your browser using DataLab