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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)