Kai Yu asks:
I am trying to build a tree model using rpart. I need a way to get the
tree with any given number of splits. Checking the cp table (using
printcp) can't help in many cases. For example, given the following CP
table,
CP nsplit rel error xerror xstd
1 0.050633 0 1.00000 1.0000 0.036718
2 0.035443 1 0.94937 1.0734 0.036796
3 0.022785 3 0.87848 1.0810 0.036794
4 0.020253 7 0.78228 1.0633 0.036795
I can't get a tree with the best 2 splits.
----------------------------------------------------------
No, you can't get said tree. Neither can I.
You need to read the tree literature (I'd recommend the CART book by
Brieman, Friedman, Olshen and Stone).
In the case you display, there is not a `best' 2 split tree according to
the complexity ordering. If you did summary(fit) you would notice that
every split is labeled with a complexity parameter, and that some of them
are tied. Hence there is no cutoff value that trims exactly the number
of nodes that you desire.
Terry Therneau
|