Learn R Programming

adabag (version 2.1)

predict.bagging: Predicts from a fitted Bagging object

Description

Classifies a dataframe using a fitted bagging object.

Usage

## S3 method for class 'bagging':
predict(object, newdata, ...)

Arguments

object
fitted model object of class bagging. This is assumed to be the result of some function that produces an object with the same named components as that returned by the bagging function.
newdata
data frame containing the values at which predictions are required. The predictors referred to in the right side of formula(object) must be present by name in newdata.
...
further arguments passed to or from other methods.

Value

  • An object of class predict.bagging, which is a list with the following components:
  • formulathe formula used.
  • votesa matrix describing, for each observation, the number of trees that assigned it to each class.
  • 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, bagging.cv

Examples

Run this code
library(rpart)
data(iris)
names(iris)<-c("LS","AS","LP","AP","Especies")
sub <- c(sample(1:50, 25), sample(51:100, 25), sample(101:150, 25))
iris.bagging <- bagging(Especies ~ ., data=iris[sub,], mfinal=10)
iris.predbagging<- predict.bagging(iris.bagging, newdata=iris[-sub,])

## 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(minsplit=15))
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