If there are only categorical variables in the dataset, will the depth of the decision tree be equal to the number of attributes? If not, can a value be split again?
2 Answers
A variable can be split multiple times. This is part of what makes decision trees so powerful. Have a look at this example which uses a decision tree to model a sine wave. [1]
However, often it is a good idea to split a categorical variable into multiple dummy variables. This is especially true when there are many categories without a particular order involved for a variable. It should be easier for the tree construction algorithm to recognize predictive value in a dummy variable using a single split rather than by making two splits to isolate the category in the original variable.
[1] - http://scikit-learn.org/stable/auto_examples/tree/plot_tree_regression.html
-
$\begingroup$ But see also stats.stackexchange.com/questions/410939/… $\endgroup$ Commented Mar 25, 2020 at 0:31
First of all, it might be less than number of attributes when one of your attributes lose importance when others have been used due to some kind of dependence among them. Depending on the implementation, it might be larger also when branching is done like "Blue/Not Blue" at each level. But, typically, each categorical feature is handled in a single node (level), so you'll probably have depth $\leq$ number of features.