Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以获得R中用于随机森林树分类的实例?_R_Machine Learning_Random Forest_Feature Extraction_Feature Selection - Fatal编程技术网

有没有一种方法可以获得R中用于随机森林树分类的实例?

有没有一种方法可以获得R中用于随机森林树分类的实例?,r,machine-learning,random-forest,feature-extraction,feature-selection,R,Machine Learning,Random Forest,Feature Extraction,Feature Selection,R中randomForest包中的getTree函数显示随机林中使用的特定树的结构 下面是iris数据集的一个示例 library(randomForest) data(iris) rf <- randomForest(Species ~ ., iris) getTree(rf, 1) 叶是具有0个叶子节点和0个右子节点的节点 有什么方法可以得到哪些实例(iris数据集的行)在这些叶子中吗? 与节点2一样,节点2是一片叶子,iris数据集中的实例2、3、4都分类为1 任何帮助都将不胜感激

R中randomForest包中的
getTree
函数显示随机林中使用的特定树的结构

下面是iris数据集的一个示例

library(randomForest)
data(iris)
rf <- randomForest(Species ~ ., iris)
getTree(rf, 1)
叶是具有0个叶子节点和0个右子节点的节点

有什么方法可以得到哪些实例(iris数据集的行)在这些叶子中吗?
与节点2一样,节点2是一片叶子,iris数据集中的实例2、3、4都分类为1


任何帮助都将不胜感激。

基于此答案:

可能有一个我不知道的访问功能,但以下手动方法似乎有效:

rf <- randomForest(Species ~ ., iris, keep.forest=TRUE)
pr_nodes <- attr(predict(rf, iris, nodes=TRUE),'nodes')

pr_nodes[,1] # array of 150 node assignments for 1st of 500 trees

rf谢谢,但您能解释一下代码的第二行吗?什么是attr?为什么要写nodes=TRUE?如果您能稍微解释一下您的代码,这将非常有帮助。感谢you@rmania您会发现
帮助
(或
)功能非常有用。例如,尝试
help(attr)
以了解
attr()
的作用,或
预测
以了解
节点=TRUE
的作用。我可以剪切和粘贴文档,但是如果你有一个R控制台,它就在你面前。不,我了解attr和predict的功能,我只想了解使用predict函数获取实例背后的逻辑。据我所知,预测函数用于根据RF结果进行预测,但它如何帮助获得实例?对不起,如果这是一个愚蠢的问题,但我只是有一点confused@C8H10N4O2我对此也很感兴趣,使用predict函数获取实例背后的逻辑是什么。Doesnt predict函数用于根据RF结果进行预测?它在获取实例时有何用处?
rf <- randomForest(Species ~ ., iris, keep.forest=TRUE)
pr_nodes <- attr(predict(rf, iris, nodes=TRUE),'nodes')

pr_nodes[,1] # array of 150 node assignments for 1st of 500 trees