Main Content

oobPredict

Predict out-of-bag labels and scores of bagged classification ensemble

Description

[labels,scores] = oobPredict(ens) returns class labels and scores for the out-of-bag data in ens.

example

[labels,scores] = oobPredict(ens,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify the indices of the weak learners to use for calculating the predicted labels.

Examples

collapse all

Find the out-of-bag predictions and scores for the Fisher iris data. Find the scores with notable uncertainty in the resulting classifications.

Load the sample data set.

load fisheriris

Train an ensemble of bagged classification trees.

ens = fitcensemble(meas,species,'Method','Bag');

Find the out-of-bag predictions and scores.

[label,score] = oobPredict(ens);

Find the scores in the range (0.2,0.8). These scores have notable uncertainty in the resulting classifications.

unsure = ((score > .2) & (score < .8));
sum(sum(unsure))  % Number of uncertain predictions
ans = 
16

Input Arguments

collapse all

Bagged classification ensemble model, specified as a ClassificationBaggedEnsemble model object trained with fitcensemble.

Name-Value Arguments

collapse all

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

Indices of the weak learners in the ensemble to use with oobPredict, specified as a vector of positive integers in the range [1:ens.NumTrained]. By default, the function uses all learners.

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 oobPredict 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.

For each observation in X, the predicted class label corresponds to the minimum expected classification cost among all classes. For an observation with NaN scores, the function classifies the observation into the majority class, which makes up the largest proportion of the training labels.

  • The label is the class with the highest score. In case of a tie, the label is earliest in ens.ClassNames.

  • labels has the same data type as the observed class labels (Y) used to train ens. (The software treats string arrays as cell arrays of character vectors.)

  • The length of labels is equal to the number of rows of ens.X.

Class scores, returned as a numeric matrix with one row per observation and one column per class. For each observation and each class, the score represents the confidence that the observation originates from that class. A higher score indicates a higher confidence. Score values are in the range 0 to 1. For more information, see Score (ensemble).

More About

collapse all

Extended Capabilities

expand all

Version History

Introduced in R2012b