prune.misclass
is an abbreviation for
prune.tree(method=misclass)
for use with the function
cv.tree
.
k
is supplied, the optimal subtree is returned.
prune.tree(tree, k=NULL, best=NULL, newdata, nwts, method="deviance", loss, eps=1e-3) prune.misclass(tree, k=NULL, best=NULL, newdata, nwts, loss, eps=1e-3)
"tree"
.
This is assumed to be the result of some function that produces
an object with the same named
components as that returned by the
tree
function.
tree
(
k
a scalar) or the (optional) sequence of subtrees minimizing the cost-complexity measure
(
k
a vector). If missing,
k
is determined algorithmically.
k
.
If there is no tree in the sequence of the requested size,
the next largest is returned.
newdata
cases.
deviance
is accepted.
For classification trees, the default is
deviance
and the alternative is
misclass
(misclassification error rate).
newdata
.
k
is supplied and is a scalar, a
tree
object is returned
that minimizes the cost-complexity measure for that
k
.
If
best
is supplied, a
tree
object of size
best
is returned.
Otherwise, an object of class
tree.sequence
is returned.
The object contains the following components:
-Inf
, its lowest possible bound.
"deviance"
or
"misclass"
depending on the
input value of
method
.
The response as well as the predictors referred to in the right side
of the formula in
tree
must be present by name in
newdata
.
These data are dropped down each tree in the cost-complexity sequence
and deviances calculated by comparing the supplied response to the prediction.
The function
cv.tree
routinely uses the
newdata
argument in
cross-validating the pruning procedure.
A
plot
method exists for objects of this class.
It displays the value of the deviance or number of
mis-classifications for each subtree in the cost-complexity sequence.
An additional axis displays the values of the cost-complexity parameter at each subtree.
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