简体   繁体   English

如何从随机森林中获取树信息,打包“ party”

[英]How to get tree information from random forest, package 'party'

I am using R package 'party'. 我正在使用R包“ party”。 Is there any method to access information of individual tree? 有什么方法可以访问单个树的信息? Such as which samples (which features are selected, and times) are used for creating the tree, which are the OOB samples, what is the OOB error of the tree. 例如使用哪些样本(选择了哪些特征和时间)来创建树,哪些是OOB样本,那么树的OOB误差是多少。 The package 'randomForest' seems to provide part but not complete information. 包“ randomForest”似乎提供了部分信息,但没有提供完整的信息。 Though RF is a black box, but it could be brighter I think. 尽管RF是一个黑匣子,但我认为它可能会更亮。

Function getTree(rfobj, k=1, labelVar=FALSE) gives the detailed information of each tree. 函数getTree(rfobj,k = 1,labelVar = FALSE)给出每棵树的详细信息。 You can print the entire random forest to local file, for example, the following code will print all the information of each tree into a .csv file. 您可以将整个随机森林打印到本地文件,例如,以下代码会将每棵树的所有信息打印到.csv文件中。

for (i in 1:RandomForestObject$ntree){
    treeFileName <- paste(outputFileDir,'/',forestName,"_tree_", i, '.csv', sep="")
    tree<-getTree(RandomForestObject,i,labelVar=TRUE)
    write.csv(tree, file=treeFileName)
}

Check attributes(RandomForestObj), the 'err.rate' is providing error rate of each tree for each class, this is also what is shown when you plot the error rate of entire forest. 检查属性(RandomForestObj),“ err.rate”为每个类提供每棵树的错误率,这也是在绘制整个森林的错误率​​时显示的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM