Main Content

resubPredict

Predict response of regression ensemble by resubstitution

Description

example

Yfit = resubPredict(ens) returns a vector of ens.X elements containing the responses predicted by ens for the data ens.X. Yfit contains the predictions of ens on the data used by fitrensemble to create ens.

Yfit = resubPredict(ens,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify the indices of weak learners for predicting responses, and whether to perform computations in parallel.

Examples

collapse 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.

resubLoss(ens)
ans = 0.5836

Input Arguments

collapse all

Regression ensemble model, specified as a RegressionEnsemble model object trained 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.

Example: resubPredict(ens,Learners=[1 2 3 5],UseParallel=true) specifies to use the first, second, third, and fifth learners in the ensemble, and to perform computations in parallel.

Indices of weak learners in the ensemble to use in resubPredict, 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

Flag to run in parallel, specified as a numeric or logical 1 (true) or 0 (false). If you specify UseParallel=true, the resubPredict function executes for-loop iterations by using parfor. The loop runs in parallel when you have Parallel Computing Toolbox™.

Example: UseParallel=true

Data Types: logical

Output Arguments

collapse all

Predicted response values, returned as a numeric column vector with the same number of rows as X. Each row of Yfit gives the predicted response to the corresponding row of X, based on the regression model ens.

Extended Capabilities

Version History

Introduced in R2011a