Main Content


Resubstitution classification margins for classification ensemble model



m = resubMargin(ens) returns the resubstitution classification margins m for the trained classification ensemble model ens using the training data stored in ens.X and the corresponding true class labels stored in ens.Y. m is returned as a numeric column vector with the same length as ens.Y. The software estimates each entry of m using the trained classification ensemble model ens, the corresponding row of ens.X, and the true class label ens.Y.

m = resubMargin(ens,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify the indices of trained weak learners to use for calculating the loss, and whether to run computations in parallel.


collapse 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

Input Arguments

collapse all

Classification ensemble model, specified as a ClassificationEnsemble 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: resubmargin(ens,Learners=[1 2 3 5],UseParallel=true) specifies to use the first, second, third, and fifth learners in the ensemble in resubMargin, and to perform computations in parallel.

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

Flag to run in parallel, specified as a numeric or logical 1 (true) or 0 (false). If you specify UseParallel=true, the resubMargin 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

More About

collapse all


The classification margin is the difference between the classification score for the true class and maximal classification score for the false classes. Margin is a column vector with the same number of rows as in the matrix ens.X.

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 ensemble type. For example:

  • AdaBoostM1 scores range from –∞ to ∞.

  • Bag scores range from 0 to 1.

Extended Capabilities

Version History

Introduced in R2011a

expand all