How do I interpret rpart splits on factor variables when building classification trees in R?

无人久伴 提交于 2019-12-21 16:19:35

问题


If the factor variable is Climate, with 4 possible values: Tropical, Arid, Temperate, Snow, and a node in my rpart tree is labeled as "Climate:ab", what is the split?


回答1:


I assume you use standard way to plot tree which is

plot(f)
text(f)

As you can read in help to text.rpart, argument pretty on default factor variables are presented as letters, so a means levels(Climate)[1] and it means that on left node are observation with Climate==levels(Climate)[1] and on right the others.

You could print levels directly using

plot(f)
text(f, pretty=1)

but I recommend using draw.tree from maptree package:

require(maptree)
draw.tree(f)

I used fake data to do plots:

X <- data.frame(
    y=rep(1:4,25),
    Climate=rep(c("Tropical", "Arid", "Temperate", "Snow"),25)
)
f <- rpart(y~Climate, X)


来源:https://stackoverflow.com/questions/2597310/how-do-i-interpret-rpart-splits-on-factor-variables-when-building-classification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!