Skip to main content
Notice removed Draw attention by Andrew Cassidy
Bounty Ended with Peter Calhoun's answer chosen by Andrew Cassidy
Tweeted twitter.com/StackStats/status/692403612790714369
Notice added Draw attention by Andrew Cassidy
Bounty Started worth 50 reputation by Andrew Cassidy
added 60 characters in body
Source Link
library(rpart)
tree = rpart(Kyphosis ~ ., data=kyphosis, control=rpart.control(minsplit = 1, cp = 0, xval=10))
plotcp(tree,  minline = FALSE, upper=c("splits"))

enter image description here

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? Is itIt doesn't seem to be one of the 10 made during cross validation since it's leaves contain the total dataset?

library(rpart)
tree = rpart(Kyphosis ~ ., data=kyphosis, control=rpart.control(minsplit = 1, cp = 0, xval=10))
plotcp(tree,  minline = FALSE, upper=c("splits"))

enter image description here

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? Is it one of the 10 made during cross validation?

library(rpart)
tree = rpart(Kyphosis ~ ., data=kyphosis, control=rpart.control(minsplit = 1, cp = 0, xval=10))
plotcp(tree,  minline = FALSE, upper=c("splits"))

enter image description here

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?

Source Link

How does the complexity parameter correspond to the number of splits in cross validation in rpart?

library(rpart)
tree = rpart(Kyphosis ~ ., data=kyphosis, control=rpart.control(minsplit = 1, cp = 0, xval=10))
plotcp(tree,  minline = FALSE, upper=c("splits"))

enter image description here

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? Is it one of the 10 made during cross validation?