Decision tree - Tree Depth

3 次查看(过去 30 天)
Armin Mehri
Armin Mehri 2016-10-25
As part of my project, I have to use Decision tree for classification. I am using "fitctree" function that is the Matlab function.
I want to control number of Tree and tree depth in fitctree function. anyone knows how can I do this? for example changing the number of trees to 200 and tree depth to 10. Is it possible in Decision tree changed the number of tree and tree depth or Not(why)?? If yes, How can I do this in fitctree Function ?
Best,

回答(1 个)

Ayush Aniket
Ayush Aniket 2025-6-9
For controlling tree depth in fitctree, you can set MaxDepth to directly specify the maximum tree depth, or indirectly -
  • Set MaxNumSplits to limit the number of splits (which indirectly controls depth).
  • Adjust MinLeafSize to ensure a minimum number of observations per leaf.
  • Modify MinParentSize to control when a node stops splitting.
Refer the following documentation link to read more about these arguments - https://www.mathworks.com/help/stats/fitctree.html#mw_55194c7e-3a91-4590-bdd2-c92eb1701bc1
However, fitctree is designed to create a single decision tree, so you cannot directly specify the number of trees (e.g., 200 trees) within this function. If you want to use multiple trees, you might need to switch to ensemble methods like Random Forests, which MATLAB implements using TreeBagger or fitcensemble. These functions allow you to specify the number of trees (NumTrees) and control tree depth using similar parameters. Refer the following links:
  2 个评论
Walter Roberson
Walter Roberson 2025-6-9
It sounds as if the methods you describe would set the Maximum tree depth, rather than allowing you to set a constant tree depth ? Or is it the case that if you set MaxNUmSplits to 2 and providing at least 2^10 inputs, that the tree depth will automatically become log2(2^10) == 10 ?
Ayush Aniket
Ayush Aniket 2025-6-9
编辑:Ayush Aniket 2025-6-9
The concept of constant tree depth is not applicable in decision trees. Maximum tree depth allows us to prune the tree after a certain depth. If the data is well separable before that depth, it wont reach that depth. However. if the data is not separable, the depth will be limited to the specified value.
If you set MaxNumSplits to 2 and provide enough data points, the tree won't necessarily have a constant depth of 10. Instead:
  • It limits the total number of splitting operations across the tree.
  • The actual depth depends on how those splits distribute across different branches.
  • If your data allows it, the depth could approach log₂(2^10) = 10 under optimal conditions, but it won't force a rigid depth.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by