prune
Produce sequence of classification subtrees by pruning classification tree
Description
specifies additional options using one or more name-value arguments. For example, you can
specify the pruning criterion and which branch nodes to turn into leaf nodes.tree1
= prune(tree
,Name=Value
)
Examples
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,'MinParentSize',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');
Input Arguments
tree
— Classification tree model
ClassificationTree
model object
Classification tree model, specified as a ClassificationTree
model object trained with fitctree
.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: prune(tree,Level=3,Criterion="error")
sets the pruning level
to 3 and the pruning criterion to "error".
Criterion
— Pruning criterion
"error"
(default) | "impurity"
Pruning criterion, specified as "error"
or
"impurity"
.
If you specify
"error"
, then the cost of each node is the resubstitution error for the node multiplied by the probability for the node.If you specify
"impurity"
, and you specifyPruneCriterion="impurity"
and eitherSplitCriterion="gdi"
orSplitCriterion="deviance"
when you createtree
withfitctree
, then the cost of each node is impurity for the node multiplied by the probability for the node. You cannot specify"impurity"
if you specifySplitCriterion="twoing"
when you createtree
.
.
Example: Criterion="impurity"
Data Types: char
| string
Nodes
— Branch nodes to turn into leaf nodes
numeric vector
Branch nodes to turn into leaf nodes, specified as 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.
If you specify Nodes
, you cannot specify Alpha
or
Level
.
Example: Nodes=4
Data Types: single
| double
Output Arguments
tree1
— Updated version of tree
ClassificationTree
model object
Updated version of tree
, returned as a
ClassificationTree
model object.
When you specify any name-value arguments for prune
,
tree1
is a pruned tree created from tree
using
the optimal pruning sequence.
If you do not specify any name-value arguments for prune
,
tree1
is the full, unpruned tree
, but with
optimal pruning information added. This information is useful if you create
tree
by pruning another tree, or by using the fitctree
function with Prune="off",MergeLeaves="off"
.
If you plan to prune a tree multiple times using the optimal pruning sequence, specify
Prune="on"
when you create tree
with
fitctree
.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
prune
does not execute pruning (estimation of the optimal sequence of pruned subtrees) on a GPU.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2011a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)