簡體   English   中英

情節派對決策樹

[英]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))

樹1

通過啟用text = TRUE選項,您可以獲得在條形圖上方繪制的標簽(水平)。 等效規范是text = "horizontal"text = "h" 如果您想要更窄的布局,您還可以使用:

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

tree2

頻率表很簡單:

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