prune
Produce sequence of regression subtrees by pruning regression tree
Description
Examples
Load the carsmall data set. Consider Horsepower and Weight as predictor variables.
load carsmall; X = [Weight Horsepower]; varNames = ["Weight" "Horsepower"];
Grow a regression tree using the entire data set. View the tree.
Mdl = fitrtree(X,MPG,PredictorNames=varNames)
Mdl =
RegressionTree
PredictorNames: {'Weight' 'Horsepower'}
ResponseName: 'Y'
CategoricalPredictors: []
ResponseTransform: 'none'
NumObservations: 94
Properties, Methods
view(Mdl,Mode="graph");
The regression tree has 16 pruning levels.
Prune the regression tree to pruning-level 10. View the pruned tree.
MdlPruned = prune(Mdl,Level=10);
view(MdlPruned,Mode="graph");
The pruned tree has six pruning levels.
Input Arguments
Regression tree model, specified as a RegressionTree model object trained with fitrtree.
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) specifies to prune tree
to the third level.
Pruning cost, specified as a numeric scalar from 0 (no pruning) to
1 (prune to one node). The prune
function prunes the tree to minimize the sum of (Alpha times the number
of leaf nodes) and a cost (mean squared error).
If you specify Alpha, you cannot specify Level
or Nodes.
Example: Alpha=0.1
Data Types: single | double
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=[1,3,5]
Data Types: single | double
Output Arguments
Updated version of tree, returned as a
RegressionTree 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 fitrtree 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
fitrtree.
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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- 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)