kfoldLoss - Regression loss for cross-validated kernel regression model - MATLAB (original) (raw)

Regression loss for cross-validated kernel regression model

Syntax

Description

[L](#mw%5F55d393d1-13c1-4702-8eda-a269167ff8b0) = kfoldLoss([CVMdl](#mw%5F18ffb4f0-adce-47b6-b467-24d0d3e16061)) returns the regression loss obtained by the cross-validated kernel regression modelCVMdl. For every fold, kfoldLoss computes the regression loss for observations in the validation fold, using a model trained on observations in the training fold.

example

[L](#mw%5F55d393d1-13c1-4702-8eda-a269167ff8b0) = kfoldLoss([CVMdl](#mw%5F18ffb4f0-adce-47b6-b467-24d0d3e16061),[Name,Value](#namevaluepairarguments)) returns the mean squared error (MSE) with additional options specified by one or more name-value arguments. For example, you can specify the regression-loss function or which folds to use for loss calculation.

Examples

collapse all

Simulate sample data:

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

Cross-validate a kernel regression model.

CVMdl = fitrkernel(x,y,'Kfold',5);

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

Compute the epsilon-insensitive loss for each fold for observations that fitrkernel did not use in training the folds.

L = kfoldLoss(CVMdl,'LossFun','epsiloninsensitive','Mode','individual')

L = 5×1

0.1261
0.1247
0.1107
0.1237
0.1131

Input Arguments

collapse all

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

Name-Value Arguments

collapse all

Specify optional pairs of arguments asName1=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: 'LossFun','epsiloninsensitive','Mode','individual' specifieskfoldLoss to return the epsilon-insensitive loss for each fold.

Fold indices to use for response prediction, specified as a numeric vector of positive integers. The elements of Folds must range from 1 through CVMdl.KFold.

Example: Folds=[1 4 10]

Data Types: single | double

Loss function, specified as the comma-separated pair consisting of'LossFun' and a built-in loss function name or function handle.

lossvalue = lossfun(Y,Yhat,W)  

where:

Data Types: char | string | function_handle

Since R2023b

Predicted response value to use for observations with missing predictor values, specified as "median", "mean","omitted", or a numeric scalar.

Value Description
"median" kfoldLoss uses the median of the observed response values in the training-fold data as the predicted response value for observations with missing predictor values.
"mean" kfoldLoss uses the mean of the observed response values in the training-fold data as the predicted response value for observations with missing predictor values.
"omitted" kfoldLoss excludes observations with missing predictor values from the loss computation.
Numeric scalar kfoldLoss uses this value as the predicted response value for observations with missing predictor values.

If an observation is missing an observed response value or an observation weight, then kfoldLoss does not use the observation in the loss computation.

Example: "PredictionForMissingValue","omitted"

Data Types: single | double | char | string

Output Arguments

collapse all

Cross-validated regression losses, returned as a numeric scalar or vector. The interpretation of L depends on LossFun.

To estimate L, kfoldLoss uses the data that created CVMdl.

Extended Capabilities

Version History

Introduced in R2018b

expand all

kfoldLoss fully supports GPU arrays.

Starting in R2023b, when you predict or compute the loss, some regression models allow you to specify the predicted response value for observations with missing predictor values. Specify the PredictionForMissingValue name-value argument to use a numeric scalar, the training set median, or the training set mean as the predicted value. When computing the loss, you can also specify to omit observations with missing predictor values.

This table lists the object functions that support thePredictionForMissingValue name-value argument. By default, the functions use the training set median as the predicted response value for observations with missing predictor values.

Model Type Model Objects Object Functions
Gaussian process regression (GPR) model RegressionGP, CompactRegressionGP loss, predict, resubLoss, resubPredict
RegressionPartitionedGP kfoldLoss, kfoldPredict
Gaussian kernel regression model RegressionKernel loss, predict
RegressionPartitionedKernel kfoldLoss, kfoldPredict
Linear regression model RegressionLinear loss, predict
RegressionPartitionedLinear kfoldLoss, kfoldPredict
Neural network regression model RegressionNeuralNetwork, CompactRegressionNeuralNetwork loss, predict, resubLoss, resubPredict
RegressionPartitionedNeuralNetwork kfoldLoss, kfoldPredict
Support vector machine (SVM) regression model RegressionSVM, CompactRegressionSVM loss, predict, resubLoss, resubPredict
RegressionPartitionedSVM kfoldLoss, kfoldPredict

In previous releases, the regression model loss and predict functions listed above used NaN predicted response values for observations with missing predictor values. The software omitted observations with missing predictor values from the resubstitution ("resub") and cross-validation ("kfold") computations for prediction and loss.