The original data set is 7499 obs. of 19 variables. I'm using tree
package in R to build up a classification tree. The result seems reasonable and the plot succeeded to show below:
library(tree)
tree.data = tree(Y~., data.train, control = tree.control(dim(data)[1], mincut = 10, minsize = 20, mindev = 0.001))
plot(tree.data)
text(tree.data, pretty = 0,cex=0.6)
However, when I try to use cv.tree
to prune the tree, there exits error.
cv.data = cv.tree(tree.data, FUN = prune.misclass)
Error in prune.tree(tree = list(frame = list(var = 1L, n = 6732, dev = 9089.97487458261, :
can not prune singlenode tree
Then I check the tree.data
structure.
summary(tree.data)
Classification tree:
tree(formula = Y ~ ., data = data.train, control = tree.control(dim(data)[1],
mincut = 10, minsize = 20, mindev = 0.001))
Variables actually used in tree construction:
[1] "X2" "X1" "X6" "X13" "X5" "X10" "X14" "X16" "X17" "X3" "X7" "X15" "X11" "X18"
[15] "X8" "X12"
Number of terminal nodes: 45
Residual mean deviance: 1.24 = 9243 / 7454
Misclassification error rate: 0.3475 = 2606 / 7499
This is not a single-node tree. So I'm confused why this error will appear?