[英]Plot party decision tree
如果要“查看”百分比,最簡單的方法是創建終端節點的table()
與響應,然后查看條件比例。
如果你想“看到”條形圖中的比例,那么到目前為止還沒有可能做到這一點。 但是,我調整了node_barplot()
函數以適應此功能。 因此,如果您從R-Forge重新安裝partykit
包( party
包的后繼者),您可以嘗試:
install.packages("partykit", repos = "http://R-Forge.R-project.org")
library("partykit")
為了說明,我將使用iris
數據:
ct <- ctree(Species ~ ., data = iris)
plot(ct, tp_args = list(text = TRUE))
通過啟用text = TRUE
選項,您可以獲得在條形圖上方繪制的標簽(水平)。 等效規范是text = "horizontal"
或text = "h"
。 如果您想要更窄的布局,您還可以使用:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.