简体   繁体   English

情节派对决策树

[英]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. 如果要“查看”百分比,最简单的方法是创建终端节点的table()与响应,然后查看条件比例。

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. 但是,我调整了node_barplot()函数以适应此功能。 So if you re-install the partykit package (successor of the party package) from R-Forge you can try it: 因此,如果您从R-Forge重新安装partykit包( party包的后继者),您可以尝试:

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

For illustration I will just use the iris data: 为了说明,我将使用iris数据:

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). 通过启用text = TRUE选项,您可以获得在条形图上方绘制的标签(水平)。 An equivalent specification would be text = "horizontal" or text = "h" . 等效规范是text = "horizontal"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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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