I'm using caret package to model the data using rpart package.
library('caret')
data(iris)
formula <- as.formula(Species ~.)
t <- train(formula,iris,method = "rpart",cp=0.002,maxdepth=8)
plot(t)
As a result I get object 't' and I'm trying to plot this object to get tree plot. But the result look like that:

Are there any way to make a tree plot from caret train object?
nicer looking treeplot:
library(rattle)
fancyRpartPlot(t$finalModel)

The object returned from caret::train() is a list. The element finalModel contains your model.
Try this:
plot(t$finalModel)
text(t$finalModel)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With