kfoldPredict

Predict responses for observations in cross-validated kernel regression model

Description

example

YHat = kfoldPredict(CVMdl) returns cross-validated predicted responses by the cross-validated kernel regression model CVMdl. That is, for every fold, kfoldPredict predicts the responses for observations that it holds out in validation fold while it trains using all other observations in the training fold.

Examples

collapse all

Simulate sample data:

rng(0,'twister'); % For reproducibility
n = 1000;
x = linspace(-10,10,n)';
y = 1 + x*2e-2 + sin(x)./x + 0.2*randn(n,1);

Cross-validate a kernel regression model.

CVMdl = fitrkernel(x,y,'CrossVal','on');

By default, fitrkernel implements 10-fold cross-validation. CVMdl is a RegressionPartitionedKernel model. It contains the property Trained, which is a 10-by-1 cell array holding 10 RegressionKernel models that the software trained using the training set.

Predict responses for observations that fitrkernel did not use in training the folds.

yHat = kfoldPredict(CVMdl);

yHat is a numeric vector. Display the first five predicted responses.

yHat(1:5)
ans = 5×1

1.0769
1.0744
1.0758
1.0781
1.0795

Input Arguments

collapse all

Cross-validated kernel regression model, specified as a RegressionPartitionedKernel model object. You can create a RegressionPartitionedKernel model using fitrkernel and specifying any of the one of the cross-validation name-value pair arguments, for example, CrossVal.

To obtain estimates, kfoldPredict applies the same data used to cross-validate the kernel regression model (see X input argument on fitrkernel page).

Output Arguments

collapse all

Cross-validated predicted responses, returned as an n-by-1 numeric array, where n is the number of observations in the predictor data used to create CVMdl (see X input argument on fitrkernel page).