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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'learners'

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

Default: 1:NumTrained

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.7465
   15.3398
   15.5025

More About

expand all

See Also

|