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

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 oobMargin, 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


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