Main Content

resubPredict

Classify observations in classification ensemble by resubstitution

Description

example

label = resubPredict(ens) returns a vector of predicted class labels for the trained classification ensemble model ens using the predictor data stored in ens.X. label has the same data type as the training response data ens.Y, and the same number of entries as the number of rows in ens.X.

label = resubPredict(ens,Name=Value) specifies additional options using by 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.

[label,score] = resubPredict(ens,___) additionally returns the scores for all classes, using any of the input argument combinations in the previous syntaxes.

Examples

collapse 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

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

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

Output Arguments

collapse all

Predicted class labels, returned as a categorical or character array, logical or numeric vector, or cell array of character vectors.

label has the same data type as ens.ClassNames and the same number of rows as ens.X.

Classification scores, returned as an N-by-K numeric matrix, where N is the number of rows in ens.X, and K is the number of classes in ens. A high score value indicates that an observation likely belongs to the corresponding class.

More About

collapse all

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