Predict out-of-bag response of ensemble
[label,score] = oobPredict(ens,Name,Value)
[ returns class labels
and scores for
ens for out-of-bag data.
labels and scores with additional options specified by one or more
A classification bagged ensemble, constructed with
Specify optional pairs of arguments as
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.
Indices of weak learners in the ensemble ranging from
Indication to perform inference in parallel, specified as
Classification labels of the same data type as the training data
Find Out-of-Bag Response of Classification Ensemble
Find the out-of-bag predictions and scores for the Fisher iris data. Find the scores with notable uncertainty in the resulting classifications.
Load the sample data set.
Train an ensemble of bagged classification trees.
ens = fitcensemble(meas,species,'Method','Bag');
Find the out-of-bag predictions and scores.
[label,score] = oobPredict(ens);
Find the scores in the range
(0.2,0.8). These scores have notable uncertainty in the resulting classifications.
unsure = ((score > .2) & (score < .8)); sum(sum(unsure)) % Number of uncertain predictions
ans = 16
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
predict take an average over predictions from
N out of
with replacement omits on average 37% (1/e) of
observations for each decision tree. These are "out-of-bag" observations.
For each observation,
oobLoss estimates the out-of-bag
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 out-of-bag error by comparing the out-of-bag predicted responses
against the true responses for all observations used for training.
This out-of-bag average is an unbiased estimator of the true ensemble
For ensembles, a classification score represents the confidence of a classification into a class. The higher the score, the higher the confidence.
Different ensemble algorithms have different definitions for their scores. Furthermore, the range of scores depends on ensemble type. For example:
AdaBoostM1scores range from –∞ to ∞.
Bagscores range from
Automatic Parallel Support
Accelerate code by automatically running computation in parallel using Parallel Computing Toolbox™.
To run in parallel, set the
UseParallel name-value 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).