ipred (version 0.4-0)

prune.bagging: Prune Bagged Trees

Description

Prune each of the trees in a bagging object.

Usage

## S3 method for class 'bagging':
prune(tree, cp=0.01,...)

Arguments

tree
object of class bagging (calling this tree is needed by the generic method prune in package rpart).
cp
complexity parameter, see prune.rpart.
...
additional arguments to prune.rpart.

Value

  • An object of class bagging with the pruned trees is returned.

Details

By default, bagging grows trees of maximal size. One may want to prune each tree, however, it is not clear whether or not this may decrease prediction error.

Examples

Run this code
X <- as.data.frame(matrix(rnorm(1000), ncol=10))
y <- factor(ifelse(apply(X, 1, mean) > 0, 1, 0))

mt <- bagging(y, X)
pt <- prune(mt, cp=0.01)

X <- as.data.frame(matrix(rnorm(1000), ncol=10))
y <- factor(ifelse(apply(X, 1, mean) > 0, 1, 0))

cls <- predict(mt, X)

cat("error: ", sum(y != cls)/length(cls), "")

cls <- predict(pt, X)

cat("error: ", sum(y != cls)/length(cls), "")

Run the code above in your browser using DataCamp Workspace