[R] how to put n and yprob on the tree plot ----- Re: what missed ----- CART
Uwe Ligges
ligges at statistik.tu-dortmund.de
Sun Feb 24 22:44:37 CET 2008
o ha wang wrote:
> Thanks!
>
> Yes, you were right. I loaded package 'tree'.
>
> I tried 'tree' and 'rpart' respectively, it looks like results for regression tree are same, and very similar for classification tree. (more biref using 'rpart' than using 'tree').
>
> But my problems are still not been solved using rpart.
>
> 1. how to put number (n, ie. class counts) and probability (yprob) on the plot for classification tree. There are only 0/1 on the plot. n and yprob can be seen using 'myfit' but not on the plot.
>
> 2. The notation of Numbers are overlapped for regression tree.
>
> please see my rpart code:
>
> library (rpart)
> myfit <- rpart (y ~ x1 + x2 + x3 + x4 )
> plot (myfit)); text (myfit, all= TRUE, cex=0.5, pretty=0)
> myfit
> summary(myfit)
I still cannot reproduce without y, x1, x2, x3, x4
Uwe Ligges
> thanks, xiao yue
>
>
> Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote:
>
>
> o ha wang wrote:
>> Hi all,
>>
>> Can anyone who is familar with CART tell me what I missed in my tree code?
>>
>> library (MASS)
>> myfit <- tree (y ~ x1 + x2 + x3 + x4 )
>
> There is not function tree() in MASS. I guess you have loaded package
> "tree"?
> Note that the author and maintainer of the tree package suggests to use
> package rpart instead.
>
>
>
>> # tree.screens () # useless
>> plot(myfit); text (myfit, all= TRUE, cex=0.5, pretty=0)
>> # tile.tree (myfit, fgl$type) # useless
>> # close.screen (all= TRUE) # useless
>>
>>
>> My current tree plot resulted from above code shows as:
>> 1. overlapped #s caused by unsuitable length of branch.
>> 2. no misclassification rates: 'misclass.tree' only brings up the error of ' misclassification error rate is appropriate for factor responses only', but my response y is 0/1 data.
>
> If you data is 0/1, you should make it a factor otherwise the cose will
> assume you want a regression rather than a classification tree.
>
>
>> 3. Unsuitable location of notations: there are not two notation of splitting criteria on the two branches when a node is split, instead only one notation of splitting criteria is on the node location.
>
> It indicates which items go into the left branch.
>
> Uwe Ligges
>
>
>> thanks,
>> xiao yue
>>
>>
>> ---------------------------------
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list