6

I generated a randomforest tree like below and I tried to plot it but got an error, where did I make mistake? How can I plot it in a right way?

Actmodel <- train(Activity ~ Section + Author, data = CB1, method = "ranger",trControl = trainControl(method = "cv", number = 10, verboseIter = TRUE), preProcess = c("knnImpute"))
plot(Actmodel$finalModel)
Error in xy.coords(x, y, xlabel, ylabel, log) : 
'x' is a list, but does not have components 'x' and 'y'
Sina PN
  • 131
  • 3
  • 10
  • 1
    I have the same issue. Been scouring google for half an hour now and have not found the way to plot a ranger tree. – Johan Dec 03 '16 at 20:04

1 Answers1

4

As far as I understand this it is not commonly accepted to plot the trees of random forests. This makes also sense as trees of a random forests are iterations to get optimal predictions. A plot of a single tree of a random forest is a intermediary step and might be misleading therefore. This might also be the reason why a plot functionality is not implemented in ranger.

If you want to still plot a single tree as a kind of example you have to build your model with another r package, which can be used as a workaround.

More information on this here.

https://stats.stackexchange.com/questions/41443/how-to-actually-plot-a-sample-tree-from-randomforestgettree

herter3434
  • 49
  • 2