Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

kfoldPredict

Class: RegressionPartitionedModel

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

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
Was this topic helpful?