predict.bagging {adabag} | R Documentation |

## Predicts from a fitted bagging object

### Description

Classifies a dataframe using a fitted bagging object.

### Usage

```
## S3 method for class 'bagging'
predict(object, newdata, newmfinal=length(object$trees), ...)
```

### Arguments

`object` |
fitted model object of class |

`newdata` |
data frame containing the values at which predictions are required. The predictors referred
to in the right side of |

`newmfinal` |
The number of trees of the bagging object to be used in the prediction. This argument allows the user to prune the ensemble. By default all the trees in the bagging object are used |

`...` |
further arguments passed to or from other methods. |

### Value

An object of class `predict.bagging`

, which is a list with the following components:

`formula` |
the formula used. |

`votes` |
a matrix describing, for each observation, the number of trees that assigned it to each class. |

`prob` |
a matrix describing, for each observation, the posterior probability or degree of support of each class. These probabilities are calculated using the proportion of votes in the final ensemble. |

`class` |
the class predicted by the ensemble classifier. |

`confusion` |
the confusion matrix which compares the real class with the predicted one. |

`error` |
returns the average error. |

### Author(s)

Esteban Alfaro-Cortes Esteban.Alfaro@uclm.es, Matias Gamez-Martinez Matias.Gamez@uclm.es and Noelia Garcia-Rubio Noelia.Garcia@uclm.es

### References

Alfaro, E., Gamez, M. and Garcia, N. (2013): “adabag: An R Package for Classification with Boosting and Bagging”. Journal of Statistical Software, Vol 54, 2, pp. 1–35.

Alfaro, E., Garcia, N., Gamez, M. and Elizondo, D. (2008): “Bankruptcy forecasting: An empirical comparison of AdaBoost and neural networks”. Decision Support Systems, 45, pp. 110–122.

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

### Examples

```
#library(rpart)
#data(iris)
#sub <- c(sample(1:50, 25), sample(51:100, 25), sample(101:150, 25))
#iris.bagging <- bagging(Species ~ ., data=iris[sub,], mfinal=5)
#iris.predbagging<- predict.bagging(iris.bagging, newdata=iris[-sub,])
#iris.predbagging
## 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=5,
control=rpart.control(maxdepth=3))
BC.bagging.pred <- predict.bagging(BC.bagging,newdata=BreastCancer[-sub,-1])
BC.bagging.pred$prob
BC.bagging.pred$confusion
BC.bagging.pred$error
```

*adabag*version 5.0 Index]