策划党决策树 [英] 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.
如果您想看到" 在条形图中的比例,那么到目前为止,尚不可能这样做.但是,我调整了node_barplot()
函数以适应此功能.因此,如果您从R-Forge重新安装partykit
软件包(party
软件包的后继产品),则可以尝试以下操作:
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")
为说明起见,我将仅使用iris
数据:
For illustration I will just use the iris
data:
ct <- ctree(Species ~ ., data = iris)
plot(ct, tp_args = list(text = TRUE))
通过启用text = TRUE
选项,可以将标签绘制在横条上方(水平).等效的规格为text = "horizontal"
或text = "h"
.如果您想缩小布局,也可以使用:
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))
频率表很简单:
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
这篇关于策划党决策树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!