# How is cross validation used to prune a decision tree

As I understand it one can use cross validation to help find the optimal pruning of a classification or regression tree, for example, implemented here in Matlab.

I do not understand the following about this process. Since each cross validation fold has random data, it may be that the trees fit on each data set may be different and have differing depths. How can one find the best pruning level over all such trees then?

• I think that the answer wants to say: take the pruning depth as another parameter to tweak, i.e. take a tree algorithm with a fixed set of parameters (i.e. depth is fixed) and then let it run over different data sets and compute some function (usually the mean) of the performances over all the data sets and assign this as the total performance of this parameter setting. Oct 26 '15 at 9:06
• Take a look at ID3 algorithm used to generate a decision tree from a database en.wikipedia.org/wiki/ID3_algorithm Aug 30 '16 at 8:38

Personally, I use sklearn which does not have this feature. So, I just do a grid search for several values of max_depth and use whatever maximizes accuracy or whatever score I want.