1
votes

As part of my project, I have to use Decision tree that I am using "fitctree" function that is the Matlab function for classified my features that extracted with PCA.

I want to control number of Tree and tree depth in fitctree function. anyone knows how can I do this? for example changed the number of trees to 200 and tree depth to 10. How am I going to do this? Is it possible to change these value in decision tree?

Best,

2

2 Answers

2
votes

fitctree offers only input parameters to control the depth of the resulting tree:

  • MaxNumSplits
  • MinLeafSize
  • MinParentSize

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

You have to play with those parameters to control the depth of your tree. Thats because the decision tree only stops growing when purity is reached.

Another possibility would be to turn on pruning. Pruning will reduce the size of your tree by removing sections of the tree that provide little power to classify instances.

0
votes

Let me assume that you are using ID3 algorithm. Its pseudocode can provide a way to control the depth of the tree.

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

What algorithm does your fictree function try to implement?