Main Content


Classification margins by resubstitution


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


margin = resubMargin(ens) returns the classification margin obtained by ens on its training data.

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

Input Arguments


A classification ensemble created 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. resubMargin 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) containing the classification margins.


expand all

Find the resubstitution margins for an ensemble that classifies the Fisher iris data.

Load the Fisher iris data set.

load fisheriris

Train an ensemble of 100 boosted classification trees using AdaBoostM2.

t = templateTree('MaxNumSplits',1); % Weak learner template tree object
ens = fitcensemble(meas,species,'Method','AdaBoostM2','Learners',t);

Find the resubstitution margins.

margin = resubMargin(ens);
[min(margin) mean(margin) max(margin)]
ans = 1×3

   -0.5674    3.2486    4.6245

More About

expand all

Extended Capabilities