Main Content


Predict out-of-bag response of ensemble


[label,score] = oobPredict(ens)
[label,score] = oobPredict(ens,Name,Value)


[label,score] = oobPredict(ens) returns class labels and scores for ens for out-of-bag data.

[label,score] = oobPredict(ens,Name,Value) computes labels and scores with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all


A classification bagged ensemble, constructed 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.

Indices of weak learners in the ensemble to use in oobPredict, 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

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 labels of the same data type as the training data Y. (The software treats string arrays as cell arrays of character vectors.) There are N elements or rows, where N is the number of training observations. The label is the class with the highest score. In case of a tie, the label is earliest in ens.ClassNames.


An N-by-K numeric matrix for N observations and K classes. A high score indicates that an observation is likely to come from this class. Scores are in the range 0 to 1.


expand all

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

More About

expand all

Extended Capabilities