If k is supplied, the optimal subtree is returned.
prune.tree(tree, k = NULL, best = NULL, newdata, method = c("deviance", "misclass")[1], eps = 1e-3) prune.misclass(tree, k = NULL, best = NULL, newdata, eps = 1e-3)
z.auto <- tree(Mileage ~ Weight, car.test.frame)zp <- prune.tree(z.auto) # determine the cost complexity pruning sequence plot(zp) # plot it on current graphics device z5.auto <- prune.tree(z.auto, best = 5) # select the best 5 node subtree