Main Content


Predict out-of-bag response of ensemble


Yfit = oobPredict(ens)
Yfit = oobPredict(ens,Name,Value)


Yfit = oobPredict(ens) returns the predicted responses for the out-of-bag data in ens.

Yfit = oobPredict(ens,Name,Value) predicts responses with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all


A regression bagged ensemble, constructed with fitrensemble.

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 to use in oobPredict, 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

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.

Output Arguments


A vector of predicted responses for out-of-bag data. Yfit has size(ens.X,1) elements.

You can find the indices of out-of-bag observations for weak learner L with the command



expand all

Compute the out-of-bag predictions for the carsmall data set. Display the first three terms of the fit.

Load the carsmall data set and select displacement, horsepower, and vehicle weight as predictors.

load carsmall
X = [Displacement Horsepower Weight];

Train an ensemble of bagged regression trees.

ens = fitrensemble(X,MPG,'Method','Bag');

Find the out-of-bag predictions, and display the first three terms of the fit.

Yfit = oobPredict(ens);
Yfit(1:3) % First three terms
ans = 3×1


More About

expand all

Extended Capabilities

See Also