[英]Plot party decision tree
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))
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))
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.