简体   繁体   English

使用和理解MATLAB的TreeBagger(随机森林)方法

[英]Using and understanding MATLAB's TreeBagger (a random forest) method

I'm trying to use MATLAB's TreeBagger method, which implements a random forest. 我正在尝试使用MATLAB的TreeBagger方法,该方法实现了一个随机森林。

I get some results, and can do a classification in MATLAB after training the classifier. 我得到了一些结果,并且可以在训练分类器之后在MATLAB中进行分类。 However I'd like to "see" the trees, or want to know how the classification works. 但是,我想“看”这些树,或者想知道分类的工作原理。

For example, let's run this minimal example, I found here: Matlab treebagger example 例如,让我们运行这个最小的示例,我在这里找到: Matlab treebagger示例

So, I end up with a classificator stored in "B". 因此,我最终得到了存储在“ B”中的分类器。 How can I inspect the trees? 如何检查树木? Like having a look at each node, to see on which criteria (eg feature) the decision is made? 就像查看每个节点一样,看看是根据哪个标准(例如要素)做出决定的? Entering B returns: 输入B返回:

B = 

  TreeBagger
Ensemble with 20 bagged decision trees:
           Training X:                [6x2]
           Training Y:                [6x1]
               Method:       classification
                Nvars:                    2
         NVarToSample:                    2
              MinLeaf:                    1
                FBoot:                    1
SampleWithReplacement:                    1
 ComputeOOBPrediction:                    0
     ComputeOOBVarImp:                    0
            Proximity:                   []
           ClassNames:             '0'             '1'

I can't see something like B.trees or so. 我看不到B.trees东西。

And a follow-up question would be: How to port your random-forest code you prototyped in MATLAB to any other language. 接下来的问题是:如何将您在MATLAB中原型化的随机森林代码移植到任何其他语言。 Then you need to know how each tree works, so you can implement it in the target language. 然后,您需要了解每棵树的工作方式,以便可以用目标语言实现它。

I hope you get the point, or understand my query ;) 希望您能理解,或理解我的询问;)

Thanks for answers! 感谢您的回答!

Best, Patrick 最好的,帕特里克

Found out how to inspect the trees, by running the view() command. 通过运行view()命令了解如何检查树。 Eg for inspecting the first tree of the example: 例如,检查示例的第一棵树:

>> view(B.Trees{1})
Decision tree for classification
1 if x2<650 then node 2 elseif x2>=650 then node 3 else 0
2 if x1<4.5 then node 4 elseif x1>=4.5 then node 5 else 1
3 class = 0
4 class = 0
5 class = 1

By passing some more arguments to the view() command, the tree can also be visualized: 通过将更多参数传递给view()命令,也可以将树可视化:

view(B.Trees{1},'mode','graph')

在此处输入图片说明

to view multiple trees just use loop : 要查看多棵树,只需使用loop:

for n=1:30 %number of tree
view(t.Trees{n});
end

you can find the source here 你可以在这里找到源

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

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