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
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
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".
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 createtreewithfitctree, 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
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
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
Usage notes and limitations:
prunedoes 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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)