prune

Class: ClassificationTree

Produce sequence of subtrees by pruning

Syntax

`tree1 = prune(tree)tree1 = prune(tree,Name,Value)`

Description

`tree1 = prune(tree)` creates a copy of the classification tree `tree` with its optimal pruning sequence filled in.

`tree1 = prune(tree,Name,Value)` creates a pruned tree with additional options specified by one `Name,Value` pair argument. You can specify several name-value pair arguments in any order as `Name1,Value1,…,NameN,ValueN`.

Tips

• `tree1 = prune(tree)` returns the decision tree `tree1` that is the full, unpruned `tree`, but with optimal pruning information added. This is useful only if you created `tree` by pruning another tree, or by using the `fitctree` function with pruning set `'off'`. If you plan to prune a tree multiple times along the optimal pruning sequence, it is more efficient to create the optimal pruning sequence first.

Input Arguments

 `tree` A classification tree created with `fitctree`.

Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside single quotes (`' '`). You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

 `'Alpha'` A numeric scalar. `prune` prunes `tree` to the specified value of the pruning cost. `'Level'` A numeric scalar from `0` (no pruning) to the largest pruning level of this tree `max(tree.PruneList)`. `prune` returns the tree pruned to this level. `'Nodes'` A numeric vector with elements from `1` to `tree.NumNodes`. Any `tree` branch nodes listed in `nodes` become leaf nodes in `tree1`, unless their parent nodes are also pruned.

Output Arguments

 `tree1` A classification tree.

Examples

collapse all

Prune and Display a Classification Tree

Construct and display a full classification tree for Fisher's iris data.

```load fisheriris; varnames = {'SL' 'SW' 'PL' 'PW'}; t1 = fitctree(meas,species,... 'minparent',5,'predictornames',varnames); view(t1,'mode','graph');```

Construct and display the next largest tree from the optimal pruning sequence.

```t2 = prune(t1,'level',1); view(t2,'mode','graph');```