决策树深度

Decision Tree Depth

作为我项目的一部分,我必须使用决策树,我正在使用 "fitctree" 函数,这是 Matlab 函数,用于对使用 PCA 提取的特征进行分类。

我想在 fitctree 函数中控制 树的数量树的深度。 任何人都知道我该怎么做?例如,将树的数量更改为 200,将树的深度更改为 10。我该怎么做? 是否可以在决策树中更改这些值?

最佳,

假设您使用的是 ID3 算法。它的 pseudocode 可以提供一种控制树深度的方法。

ID3 (Examples, Target_Attribute, Attributes, **Depth**)
// Check the depth of the tree, if it is 0, we are going to break 
if (Depth == 0) { break; }

// Else continue
Create a root node for the tree
If all examples are positive, Return the single-node tree Root, with label = +.
If all examples are negative, Return the single-node tree Root, with label = -.
If number of predicting attributes is empty, then Return the single node tree Root,
with label = most common value of the target attribute in the examples.
Otherwise Begin
    A ← The Attribute that best classifies examples.
    Decision Tree attribute for Root = A.
    For each possible value, vi, of A,
        Add a new tree branch below Root, corresponding to the test A = vi.
        Let Examples(vi) be the subset of examples that have the value vi for A
        If Examples(vi) is empty
            Then below this new branch add a leaf node with label = most common target value in the examples

        // We decrease the value of Depth by 1 so the tree stops growing when it reaches the designated depth
        Else below this new branch add the subtree ID3 (Examples(vi), Target_Attribute, Attributes – {A}, Depth - 1)
End
Return Root

你的 fictree 函数试图实现什么算法?

fitctree 仅提供输入参数来控制结果树的深度:

  • MaxNumSplits
  • 最小叶尺寸
  • 最小父级大小

https://de.mathworks.com/help/stats/classification-trees-and-regression-trees.html#bsw6baj

您必须使用这些参数来控制树的深度。那是因为决策树只有在达到纯度时才会停止生长。

另一种可能性是打开修剪。修剪将通过移除树中几乎无法对实例进行分类的部分来减小树的大小。