简体   繁体   中英

Plot party decision tree

I have the following plot as you can see in the picture, Is there any way to see exact number of percentage in the leaf nodes?

在此输入图像描述

If you want to "see" the percentages, the easiest way is to make a table() of the terminal nodes vs. the response and then look at the conditional proportions.

If you want to "see" the proportions in the barplot, then there was no possibility to do this up to now. However, I tweaked the node_barplot() function to accomodate this feature. So if you re-install the partykit package (successor of the party package) from R-Forge you can try it:

install.packages("partykit", repos = "http://R-Forge.R-project.org")
library("partykit")

For illustration I will just use the iris data:

ct <- ctree(Species ~ ., data = iris)
plot(ct, tp_args = list(text = TRUE))

树1

By enabling the text = TRUE option you get the labels drawn above the bars (horizontally). An equivalent specification would be text = "horizontal" or text = "h" . If you want a narrower layout you could also use:

plot(ct, tp_args = list(text = "vertical", ymax = 1.5))

tree2

And the frequency table is simply:

tab <- table(predict(ct, type = "node"), iris$Species)
prop.table(tab, 1) * 100
##         setosa versicolor  virginica
##   2 100.000000   0.000000   0.000000
##   5   0.000000  97.826087   2.173913
##   6   0.000000  50.000000  50.000000
##   7   0.000000   2.173913  97.826087

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM