library(rpart)
tree = rpart(Kyphosis ~ ., data=kyphosis, control=rpart.control(minsplit = 1, cp = 0, xval=10))
plotcp(tree, minline = FALSE, upper=c("splits"))
From what I understand xval=10 corresponds to 10-fold cross validation. So the rpart algorithm will build 10 different trees (not pruned and until all training examples are classified as best as possible [controlling this with minsplit=1, cp=0]... which means my tree will potentially be overfit). Then the algorithm goes through each tree and calculates its error rate on the testing set that was held out. Next it looks through all the complexity parameters (cp) and determines how the tree would have done on the testing set had that complexity parameter (cp) been used. My questions:
How does the number of splits directly correspond to a complexity parameter? Aren't there 10 different trees being built and the complexity parameter would work differently on each?
What is the final tree that is returned? It doesn't seem to be one of the 10 made during cross validation since it's leaves contain the total dataset?