Main Content


Predict response of ensemble by resubstitution


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


Yfit = resubPredict(ens) returns the response ens predicts for the data ens.X. Yfit is the predictions of ens on the data that fitrensemble used to create ens.

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

Input Arguments


A regression ensemble created 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 ranging from 1 to ens.NumTrained. resubPredict uses only these learners for calculating loss.

Default: 1:NumTrained


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


A vector of predicted responses to the training data, with ens.X elements.


expand all

Find the resubstitution predictions of mileage from the carsmall data, and look at their mean-squared difference from the training data.

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

load carsmall
X = [Horsepower Weight];

Train an ensemble of regression trees.

ens = fitrensemble(X,MPG,'Method','LSBoost','Learners','Tree');

Find the resubstitution predictions of MPG.

Yfit = resubPredict(ens);

Calculate the mean-squared difference of the resubstitution predictions from the training data.

MSE = mean((Yfit - ens.Y).^2)
MSE = 0.5836

Confirm that the result is the same as the result of resubLoss.

ans = 0.5836

Extended Capabilities