oobPredict
Predict out-of-bag labels and scores of bagged classification ensemble
Description
[
specifies additional options using one or more name-value arguments. For example,
you can specify the indices of the weak learners to use for calculating the
predicted labels.labels
,scores
]
= oobPredict(ens
,Name=Value
)
Examples
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.
load fisheriris
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
Input Arguments
ens
— Bagged classification ensemble model
ClassificationBaggedEnsemble
model object
Bagged classification ensemble model, specified as a ClassificationBaggedEnsemble
model object trained with fitcensemble
.
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: oobPredict(ens,Learners=[1 2 3 5],UseParallel=true)
specifies to use the first, second, third, and fifth learners in the ensemble, and
to perform computations in parallel.
Learners
— Indices of weak learners
[1:ens.NumTrained]
(default) | vector of positive integers
Indices of the weak learners in the ensemble to use with
oobPredict
, specified as a
vector of positive integers in the range
[1:ens.NumTrained
]. By default,
the function uses all learners.
Example: Learners=[1 2 4]
Data Types: single
| double
UseParallel
— Flag to run in parallel
false
or 0
(default) | true
or 1
Flag to run in parallel, specified as a numeric or logical 1
(true
) or 0 (false
). If you specify
UseParallel=true
, the oobPredict
function executes
for
-loop iterations by using parfor
. The loop runs in parallel when you have Parallel Computing Toolbox™.
Example: UseParallel=true
Data Types: logical
Output Arguments
labels
— Predicted class labels
categorical array | character array | logical vector | numeric vector | cell array of character vectors
Predicted class labels, returned as a categorical or character array, logical or numeric vector, or cell array of character vectors.
For each observation in X
, the predicted class label
corresponds to the minimum expected classification cost among all classes.
For an observation with NaN
scores, the
function classifies the observation into the majority class, which makes up the largest
proportion of the training labels.
The label is the class with the highest score. In case of a tie, the label is earliest in
ens
.ClassNames
.labels
has the same data type as the observed class labels (Y
) used to trainens
. (The software treats string arrays as cell arrays of character vectors.)The length of
labels
is equal to the number of rows ofens.X
.
scores
— Class scores
numeric matrix
Class scores, returned as a numeric matrix with one row per observation
and one column per class. For each observation and each class, the score
represents the confidence that the observation originates from that class. A
higher score indicates a higher confidence. Score values are in the range
0
to 1
. For more information, see
Score (ensemble).
More About
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 data set,
fitcensemble
generates many bootstrap
replicas of the data set 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 data set 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 "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
error.
Score (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 the ensemble type. For example:
AdaBoostM1
scores range from –∞ to ∞.Bag
scores range from0
to1
.
Extended Capabilities
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).
Version History
Introduced in R2012b
See Also
oobMargin
| oobLoss
| oobEdge
| predict
| ClassificationBaggedEnsemble
| fitcensemble
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)