Out-of-bag regression error


L = oobLoss(ens)
L = oobLoss(ens,Name,Value)


L = oobLoss(ens) returns the mean squared error for ens computed for out-of-bag data.

L = oobLoss(ens,Name,Value) computes error with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.

Input Arguments


A regression bagged ensemble, constructed with fitrensemble.

Name-Value Pair Arguments



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

Default: 1:NumTrained


Function handle for loss function, or 'mse', meaning mean squared error. If you pass a function handle fun, oobLoss calls it as


where Y, Yfit, and W are numeric vectors of the same length. Y is the observed response, Yfit is the predicted response, and W is the observation weights.

Default: 'mse'


Character vector or string scalar representing the meaning of the output L:

  • 'ensemble'L is a scalar value, the loss for the entire ensemble.

  • 'individual'L is a vector with one element per trained learner.

  • 'cumulative'L is a vector in which element J is obtained by using learners 1:J from the input list of learners.

Default: 'ensemble'

Output Arguments


Mean squared error of the out-of-bag observations, a scalar. L can be a vector, or can represent a different quantity, depending on the name-value settings.


expand all

Compute the out-of-bag error for the carsmall data.

Load the carsmall data set and select engine 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 error.

L = oobLoss(ens)
L = 18.6127

More About

expand all

See Also