在randomForest包中绘制500棵树之一 [英] plot one of 500 trees in randomForest package

查看:123
本文介绍了在randomForest包中绘制500棵树之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在R中相同名称的 randomForest 函数的输出中绘制树?例如,我使用 iris 数据,并想在500个输出树中绘制第一棵树。我的代码是

How can plot trees in output of randomForest function in same names packages in R? For example I use iris data and want to plot first tree in 500 output tress. my code is

model <-randomForest(Species~.,data=iris,ntree=500)


推荐答案

您可以使用 getTree() randomForest 包中的c $ c>函数(官方指南: https://cran.r-project.org/web/packages/randomForest/randomForest.pdf

You can use the getTree() function in the randomForest package (official guide: https://cran.r-project.org/web/packages/randomForest/randomForest.pdf)

iris 数据集上:

require(randomForest)
data(iris)

## we have a look at the k-th tree in the forest
k <- 10
getTree(randomForest(iris[, -5], iris[, 5], ntree = 10), k, labelVar = TRUE)

这篇关于在randomForest包中绘制500棵树之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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