Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a randomforest (ranger) tree in Caret

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'
like image 535
Sina PN Avatar asked Nov 11 '16 13:11

Sina PN


People also ask

Does random forest use decision tree?

A random forest is simply a collection of decision trees whose results are aggregated into one final result. Their ability to limit overfitting without substantially increasing error due to bias is why they are such powerful models.

What is Ranger random forest?

ranger: A Fast Implementation of Random Forests Ensembles of classification, regression, survival and probability prediction trees are supported. Data from genome-wide association studies can be analyzed efficiently. In addition to data frames, datasets of class 'gwaa.

How do random forests improve decision trees?

Random forests reduce the risk of overfitting and accuracy is much higher than a single decision tree. Furthermore, decision trees in a random forest run in parallel so that the time does not become a bottleneck. The success of a random forest highly depends on using uncorrelated decision trees.


1 Answers

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

like image 122
herter3434 Avatar answered Oct 08 '22 11:10

herter3434