如何在 Caret 中绘制随机森林(游侠)树 [英] How to plot a randomforest (ranger) tree in Caret

查看:105
本文介绍了如何在 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'

推荐答案

据我所知,绘制随机森林的树并不普遍.这也是有道理的,因为随机森林的树是迭代以获得最佳预测.随机森林的单棵树图是一个中间步骤,因此可能会产生误导.这也可能是游侠中未实现绘图功能的原因.

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.

如果您仍然想绘制一棵树作为一种示例,您必须使用另一个 r 包构建模型,这可以用作解决方法.

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.

这里有更多信息.

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

这篇关于如何在 Caret 中绘制随机森林(游侠)树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆