Main Content

oobPredict

Predict out-of-bag response of ensemble

Syntax

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

Description

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

ens

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.

learners

Indices of weak learners in the ensemble ranging from 1 to ens.NumTrained. oobPredict uses only these learners for calculating loss.

Default: 1:NumTrained

UseParallel

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

Yfit

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

~ens.UseObsForLearner(:,L)

Examples

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

   15.5200
   14.5558
   15.0231

More About

expand all

Extended Capabilities

See Also

|