[R] Problems with tree package
Torsten Hothorn
Torsten.Hothorn at rzmail.uni-erlangen.de
Thu Jan 31 11:39:16 CET 2002
> Hi,
> I'm getting a problem with the tree package under windows nt
> I'm using the package to produce a tree. The training set has +- 4000
> examples.
> I use the instruction
>
> hm.tr <-tree(X1~.,teste2)
>
> wich produces me this tree
>
> 1) root 4272 4037.000 0 ( 0.819288 0.180712 )
> 2) X2: 0 1640 2261.000 0 ( 0.543902 0.456098 )
> 4) X4: 0 357 170.600 1 ( 0.064426 0.935574 ) *
> 5) X4: 1 1283 1614.000 0 ( 0.677319 0.322681 )
> 10) X8: 0 849 1172.000 0 ( 0.538280 0.461720 )
> 20) X34: 0 701 965.800 1 ( 0.453638 0.546362 )
> 40) X20: 0 618 823.800 1 ( 0.385113 0.614887 )
> 80) X31: 0 516 629.100 1 ( 0.298450 0.701550 )
> 160) X3: 0 247 166.200 1 ( 0.105263 0.894737 ) *
> 161) X3: 1 269 372.300 1 ( 0.475836 0.524164 )
> 322) X35: 0 200 262.500 0 ( 0.635000 0.365000 )
> 644) X30: 0 99 131.900 1 ( 0.383838 0.616162 ) *
> 645) X30: 1 101 73.640 0 ( 0.881188 0.118812 ) *
> 323) X35: 1 69 10.450 1 ( 0.014493 0.985507 ) *
> 81) X31: 1 102 95.060 0 ( 0.823529 0.176471 ) *
> 41) X20: 1 83 25.810 0 ( 0.963855 0.036145 ) *
> 21) X34: 1 148 67.840 0 ( 0.939189 0.060811 ) *
> 11) X8: 1 434 174.100 0 ( 0.949309 0.050691 ) *
> 3) X2: 1 2632 273.300 0 ( 0.990881 0.009119 )
> 6) X9: 0 2553 152.600 0 ( 0.995300 0.004700 ) *
> 7) X9: 1 79 67.310 0 ( 0.848101 0.151899 )
> 14) X32: 0 12 6.884 1 ( 0.083333 0.916667 ) *
> 15) X32: 1 67 10.390 0 ( 0.985075 0.014925 ) *
>
> when i used this examples to classificate
>
> > classifica
> X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21
> 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> X22 X23 X24 X25 X26 X27 X28 X29 X30 X31 X32 X33 X34 X35 X36
> 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> > predict(hm.tr,classifica,"where")
> 1
> 3
> > classifica[1,2]<-0
> > predict(hm.tr,classifica,"where")
> 1
> 1
hm.tr$where corresponds to the row of hm.tr$frame where rownames codes for
the leaf numbers, e.g.
R> example(rpart)
R> fit
n= 81
node), split, n, loss, yval, (yprob)
* denotes terminal node
1) root 81 17 absent (0.7901235 0.2098765)
2) Start>=8.5 62 6 absent (0.9032258 0.0967742)
4) Start>=14.5 29 0 absent (1.0000000 0.0000000) *
5) Start< 14.5 33 6 absent (0.8181818 0.1818182)
10) Age< 55 12 0 absent (1.0000000 0.0000000) *
11) Age>=55 21 6 absent (0.7142857 0.2857143)
22) Age>=111 14 2 absent (0.8571429 0.1428571) *
23) Age< 111 7 3 present (0.4285714 0.5714286) *
3) Start< 8.5 19 8 present (0.4210526 0.5789474) *
but
R> fit$frame[,1:3]
var n wt
1 Start 81 81
2 Start 62 62
4 <leaf> 29 29
5 Age 33 33
10 <leaf> 12 12
11 Age 21 21
22 <leaf> 14 14
23 <leaf> 7 7
3 <leaf> 19 19
has the node numbers as rownames and
> fit$where
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26
9 7 9 9 3 3 3 3 3 8 8 3 9 5 3 3 3 7 3 5 3 9 8 9 9
5
...
refers to row-numbers !
Torsten
>
> i have this result.
> In the first example, as X2 is 1 and X9 is 0 shouldn't result 20?
> Is this a problem of the package or i'm i using it inciorrectly?
>
> Thanks
> Hugo
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list