rpart -- number of splits

789 views Asked by At

Using printcp I got output resembling the following (this is only a portion):

              CP nsplit rel error    xerror        xstd
1   3.254666e-01      0 1.0000000 1.0000000 0.003976889
2   5.395058e-02      1 0.6745334 0.6745334 0.003567289
3   4.125633e-02      3 0.5666322 0.5878145 0.003401065
4   1.726150e-02      4 0.5253759 0.5492028 0.003317552
5   1.222830e-02      7 0.4735914 0.4925069 0.003183022
6   1.193864e-02     10 0.4364909 0.4744730 0.003137010
7   9.243634e-03     12 0.4126137 0.4489081 0.003068901
8   5.238899e-03     13 0.4033700 0.4277007 0.003009687
9   3.878800e-03     14 0.3981311 0.4183311 0.002982702
10  3.664710e-03     16 0.3903735 0.4115054 0.002962714
11  3.261718e-03     18 0.3830441 0.4098935 0.002957953
12  2.934287e-03     20 0.3765207 0.4063421 0.002947406
13  2.871320e-03     24 0.3647835 0.4044783 0.002941839
14  2.770571e-03     25 0.3619122 0.4000201 0.002928437
15  2.052742e-03     26 0.3591416 0.3973503 0.002920351
16  1.989774e-03     28 0.3550361 0.3924892 0.002905511
17  1.813465e-03     29 0.3530464 0.3911795 0.002901486
18  1.763091e-03     30 0.3512329 0.3880563 0.002891845
19  1.737904e-03     31 0.3494698 0.3863688 0.002886609
20  1.674936e-03     32 0.3477319 0.3832708 0.002876947
21  1.670739e-03     35 0.3422915 0.3830693 0.002876317
22  1.662343e-03     39 0.3355666 0.3827167 0.002875212
23  1.653947e-03     40 0.3339042 0.3824900 0.002874502

Which value shows the total number of splits in the tree -- nsplit, or the largest index (left-most column)? (I.e., 23 or 40?)

1

There are 1 answers

0
Momemor On

The table your are seeing from the printcp function is the $cptable object from your CART model. Column "nsplit" shows the number of splits, indeed. So, you can get the total number of splits in the tree with max(carttree$cptable[,"nsplit"]) Where carttree is the name of your CART tree.