简体   繁体   English

r的决策树图中的标签为空白

[英]Labels are blank in Decision Tree plot in r

I am using caret package to train my model. 我正在使用插入符号包来训练我的模型。

My model is working fine. 我的模型工作正常。 But when I plot the decision tree, the labels are blank. 但是当我绘制决策树时,标签是空白的。 How do i get the labels? 我如何获得标签?

carMod <- train( FLAG ~.,data=df_train, method="rpart" )
plot(carMod$finalModel)

在此处输入图片说明

You need 你需要

plot(carMod$finalModel)
text(carMod$finalModel)

Use the following code, as explained on the help page for plot.rpart ( https://stat.ethz.ch/R-manual/R-devel/library/rpart/html/plot.rpart.html ): 使用以下代码,如对plot.rparthttps://stat.ethz.ch/R-manual/R-devel/library/rpart/html/plot.rpart.html )的帮助页面plot.rpart

plot(carMod$finalModel)
text(carMod$finalModel)

Alternatively use 替代使用

library(rpart.plot)
rpart.plot(carMod$finalModel)

For more information, see https://blog.revolutionanalytics.com/2013/06/plotting-classification-and-regression-trees-with-plotrpart.html 有关更多信息,请参阅https://blog.revolutionanalytics.com/2013/06/plotting-classification-and-regression-trees-with-plotrpart.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM