Hi all,
I have a problem needed your help. Here is my situation:
I fitted my data into Rpart to generate a Classification tree, and then
I printed out the Rpart objective, or best.tree. As you can see in the
attachment, with the < print(best.tree) command we can see the
"yprob" column.
I want to show the "yprob" or the Probabilities information
in the final tree graph. However, when I use the following command
>
plot(best.tree);text(best.tree,label="yprob",use.n=T,splits=T), it
generated the following error message:
Error in text.rpart(best.tree1M, use.n = T, splits = T, label =
"yprob"):
Label must be a column label of the frame component of the tree
As you can see, the tree does have a column "(yprob)" after I
input the print(best.tree) command such as (0.500000 0.500000) and (0.5525950
0.4474050).
Can any one help me solve the problem and show me how to get the
probabilities or the "yprob" column content into the final tree?
Thank you for all your help.
Xiaoxi
-----
Please see the detailed problem. Thank you.
>> printcp(best.tree1M)
Classification tree:
rpart(formula = OP1M ~ .,data = "" method = "class", parms
=list(split = "gini"))
Variables actually used in tree construction:
[1] F_5YE F_PCF ....
Root node error: 8645/17551 = 0.49256
n=17551 (489 observations deleted due to missing)
CP nsplit rel error
xerror xstd
1 0.0253326 0 1.00000 1.00000
0.0076614
2 0.0135338 1 0.97467 0.99445
0.0076607
3 0.0045113 2 0.96113 0.98427
0.0076587
........
> print(best.tree)
n=17530 (510 observations deleted due to missing)
node), split, n, loss,
yval, (yprob)
* denotes terminal node
1) root 17530 8765.0000 1 (0.5000000 0.5000000)
2) Q_1PE< 1.5 2817 1252.5980 0 (0.5525950
0.4474050) *
3) Q_1PE>=1.5 14713 7217.9020 1 (0.4900036
0.5099964)
6) H_SGG< 1.5 2800 1244.0990 0
(0.5529161 0.4470839)
12) F_PCF< 3.5 1699
655.5158 0 (0.6092234 0.3907766) *
.........
> plot(best.tree);text(best.tree,label="yprob",use.n=T,splits=T)
Error in text.rpart(best.tree1M, use.n = T, splits = T, label =
"yprob") :
Label must be a column label of the frame component of the tree
end