Main Content


Classify observations in ensemble of classification models


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


label = resubPredict(ens) returns the labels ens predicts for the data ens.X. label is the predictions of ens on the data that fitcensemble used to create ens.

[label,score] = resubPredict(ens) also returns scores for all classes.

[label,score] = resubPredict(ens,Name,Value) finds resubstitution predictions 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. resubPredict 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


The response ens predicts for the training data. label is the same data type as the training response data ens.Y, and has the same number of entries as the number of rows in ens.X.


An N-by-K matrix, where N is the number of rows in ens.X, and K is the number of classes in ens. High score value indicates that an observation likely comes from this class.


expand all

Find the total number of misclassifications of the fisheriris data for a classification ensemble.

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 total number of misclassifications.

Ypredict = resubPredict(ens); % The predictions
Ysame = strcmp(Ypredict,species); % True when Ypredict and species are equal
sum(~Ysame) % Number of different predictions
ans = 5

More About

expand all

Extended Capabilities