oobEdge
Outofbag classification edge
Syntax
edge = oobEdge(ens)
edge = oobEdge(ens,Name,Value)
Description
returns outofbag classification edge for
edge
= oobEdge(ens
)ens
.
computes classification edge with additional
options specified by one or more
edge
= oobEdge(ens
,Name,Value
)Name,Value
pair arguments.
You can specify several namevalue pair arguments
in any order as
Name1,Value1,…,NameN,ValueN
.
Input Arguments

A classification bagged ensemble,
constructed with 
NameValue Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Namevalue 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.
Learners
— Indices of weak learners
[1:ens.NumTrained]
(default)  vector of positive integers
Indices of weak learners in the ensemble to use in
oobEdge
, specified as a vector of positive integers in the range
[1:ens.NumTrained
]. By default, all learners are used.
Example: Learners=[1 2 4]
Data Types: single
 double
mode
—
Character vector or string scalar
representing the meaning of the output
L
:
'ensemble'
—L
is a scalar value, the loss for the entire ensemble.'individual'
—L
is a vector with one element per trained learner.'cumulative'
—L
is a vector in which elementJ
is obtained by using learners1:J
from the input list of learners.
UseParallel
—
Indication to perform inference in parallel, specified as false
(compute
serially) or true
(compute in parallel). Parallel computation
requires Parallel Computing Toolbox™. Parallel inference can be faster than serial inference, especially for
large datasets. Parallel computation is supported only for tree learners.
Output Arguments

Classification edge, a weighted average of the classification margin. 
Examples
Estimate OutofBag Edge
Load Fisher's iris data set.
load fisheriris
Train an ensemble of 100 bagged classification trees using the entire data set.
Mdl = fitcensemble(meas,species,'Method','Bag');
Estimate the outofbag edge.
edge = oobEdge(Mdl)
edge = 0.8767
More About
Edge
The edge is the
weighted mean value of the classification margin.
The weights are the class probabilities in
ens
.Prior
.
Margin
The classification
margin is the difference
between the classification
score for the true class
and maximal classification score for the false
classes. Margin is a column vector with the same
number of rows as in the matrix
ens
.X
.
Out of Bag
Bagging, which stands for “bootstrap aggregation”, is a
type of ensemble learning. To bag a weak learner such as a decision tree on a dataset,
fitcensemble
generates many bootstrap
replicas of the dataset and grows decision trees on these replicas. fitcensemble
obtains each bootstrap replica by randomly selecting
N
observations out of N
with replacement, where
N
is the dataset size. To find the predicted response of a trained
ensemble, predict
take an average over predictions from
individual trees.
Drawing N
out of N
observations
with replacement omits on average 37% (1/e) of
observations for each decision tree. These are "outofbag" observations.
For each observation, oobLoss
estimates the outofbag
prediction by averaging over predictions from all trees in the ensemble
for which this observation is out of bag. It then compares the computed
prediction against the true response for this observation. It calculates
the outofbag error by comparing the outofbag predicted responses
against the true responses for all observations used for training.
This outofbag average is an unbiased estimator of the true ensemble
error.
Extended Capabilities
Automatic Parallel Support
Accelerate code by automatically running computation in parallel using Parallel Computing Toolbox™.
To run in parallel, set the UseParallel
namevalue argument to
true
in the call to this function.
For more general information about parallel computing, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).
Version History
R2022a: oobEdge
returns a different value for a model with a nondefault cost matrix
If you specify a nondefault cost matrix when you train the input model object, the oobEdge
function returns a different value compared to previous releases.
The oobEdge
function uses the
observation weights stored in the W
property. The way the function uses the
W
property value has not changed. However, the property value stored in the input model object has changed for a
model with a nondefault cost matrix, so the function might return a different value.
For details about the property value change, see Cost property stores the userspecified cost matrix.
If you want the software to handle the cost matrix, prior
probabilities, and observation weights in the same way as in previous releases, adjust the prior
probabilities and observation weights for the nondefault cost matrix, as described in Adjust Prior Probabilities and Observation Weights for Misclassification Cost Matrix. Then, when you train a
classification model, specify the adjusted prior probabilities and observation weights by using
the Prior
and Weights
namevalue arguments, respectively,
and use the default cost matrix.
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)