kfoldPredict

Predict response for observations not used for training

Syntax

yfit = kfoldPredict(obj)

Description

yfit = kfoldPredict(obj) returns the predicted values for the responses of the training data based on obj, an object trained on out-of-fold observations.

Input Arguments

obj

Object of class RegressionPartitionedModel. Create obj with fitrtree or fitrensemble along with one of the cross-validation options: 'crossval', 'kfold', 'holdout', 'leaveout', or 'cvpartition'. Alternatively, create obj from a regression tree or regression ensemble with crossval.

Output Arguments

yfit

A vector of predicted values for the response data based on a model trained on out-of-fold observations.

Examples

Construct a partitioned regression model, and examine the cross-validation loss. The cross-validation loss is the mean squared error between yfit and the true response data:

load carsmall
XX = [Cylinders Displacement Horsepower Weight];
YY = MPG;
tree = fitrtree(XX,YY);
cvmodel = crossval(tree);
L = kfoldLoss(cvmodel)

L =
   26.5271

yfit = kfoldPredict(cvmodel);
mean( (yfit - tree.Y).^2 )

ans =
   26.5271