Main Content


Out-of-bag classification margins


margin = oobMargin(ens)
margin = oobMargin(ens,Name,Value)


margin = oobMargin(ens) returns out-of-bag classification margins.

margin = oobMargin(ens,Name,Value) calculates margins with additional options specified by one or more Name,Value pair arguments.

Input Arguments


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 ranging from 1 to ens.NumTrained. oobMargin uses only these learners for calculating loss.

Default: 1:NumTrained


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.

Default: false

Output Arguments


A numeric column vector of length size(ens.X,1).


expand all

Find the out-of-bag margins for a bagged ensemble from the Fisher iris data.

Load the sample data set.

load fisheriris

Train an ensemble of bagged classification trees.

ens = fitcensemble(meas,species,'Method','Bag');

Find the number of out-of-bag margins that are equal to 1.

margin = oobMargin(ens);
sum(margin == 1)
ans = 109

More About

expand all

Extended Capabilities