Predict response for observations not used for training.
yfit = kfoldPredict(obj)
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.
Object of class RegressionPartitionedModel. Create obj with RegressionTree.fit or fitensemble 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.
A vector of predicted values for the response data based on a model trained on out-of-fold observations.
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 = RegressionTree.fit(XX,YY); cvmodel = crossval(tree); L = kfoldLoss(cvmodel) L = 26.5271 yfit = kfoldPredict(cvmodel); mean( (yfit - tree.Y).^2 ) ans = 26.5271