我正在尝试为我拥有的大型数据集做一棵树。我可以运行树很好,没有收到任何错误。但是,当我看到树的标签时,它们非常混乱且不易读。另外,我觉得结果不正确。 (仅供参考,我在下面的代码中取出了一些变量,所以不仅仅是滚动所有变量,问题发生在很多或只是几个变量上)
例如,EMPLOY1拆分为on = j,但变量中的值为"无法工作","退休"等等。任何想法我做错了什么用树输出?
代码:
library(rpart)
fit <- rpat(poorhealth_cat ~
SCNTWRK1+
SCNTLWK1+
SCNTMEAL+
SCNTMONY+
SCNTPAID+
SEX+
SLEPTIM1+
SMOKE100+
SMOKDAY2+
STRENGTH+
TOLDHI2+
USENOW3+
WEIGHT2+
WTCHSALT+
FRT16+
, method="class", data=cdc) # grow tree
printcp(fit) # display the results
plotcp(fit) # visualize cross-validation results
summary(fit) # detailed summary of split
# plot unpruned tree
plot(fit,uniform=TRUE, main="Classification Tree for poorhealth_cat")
text(fit, use.n=TRUE, all=TRUE, cex=.8)
!
答案 0 :(得分:1)
我遇到了同样的问题。仍然不确定为什么,但我和#34;修复&#34;它通过使用以下代替。
#install
install.packages('rattle')
install.packages('rpart.plot')
install.packages('RColorBrewer')
#load
library(rattle)
library(rpart.plot)
library(RColorBrewer)
#plot
fancyRpartPlot(fit)
标签是对的。