# treeprune

Prune tree

`treeprune` will be removed in a future release. Use `fitctree` or `fitrtree` to grow a tree. Then use `prune` (`ClassificationTree`) or `prune` (`RegressionTree`) instead of `treeprune`.

## Syntax

`t2 = treeprune(t1,'level',level)t2 = treeprune(t1,'nodes',nodes)t2 = treeprune(t1)`

## Description

`t2 = treeprune(t1,'level',level)` takes a decision tree `t1` as created by the `treefit` function, and a pruning level, and returns the decision tree `t2` pruned to that level. Setting `level` to `0` means no pruning. Trees are pruned based on an optimal pruning scheme that first prunes branches giving less improvement in error cost.

`t2 = treeprune(t1,'nodes',nodes)` prunes the nodes listed in the `nodes` vector from the tree. Any `t1` branch nodes listed in `nodes` become leaf nodes in `t2`, unless their parent nodes are also pruned. The `treedisp` function can display the node numbers for any node you select.

`t2 = treeprune(t1)` returns the decision tree `t2` that is the same as `t1`, but with the optimal pruning information added. This is useful only if you created `t1` by pruning another tree, or by using the `treefit` function with pruning set `'off'`. If you plan to prune a tree multiple times, it is more efficient to create the optimal pruning sequence first.

Pruning is the process of reducing a tree by turning some branch nodes into leaf nodes, and removing the leaf nodes under the original branch.

## Examples

Display the full tree for Fisher's iris data, as well as the next largest tree from the optimal pruning sequence:

``` load fisheriris; t1 = treefit(meas,species,'splitmin',5); treedisp(t1,'names',{'SL' 'SW' 'PL' 'PW'});```

``` t2 = treeprune(t1,'level',1); treedisp(t2,'names',{'SL' 'SW' 'PL' 'PW'}); ```

## References

[1] Breiman, L., J. Friedman, R. Olshen, and C. Stone. Classification and Regression Trees. Boca Raton, FL: CRC Press, 1984.