kfoldPredict
Predict responses for observations in cross-validated kernel regression model
Description
uses the YHat
= kfoldPredict(CVMdl
,PredictionForMissingValue=prediction
)prediction
value as the predicted response for observations
with missing values in the predictor data. By default, kfoldPredict
uses the median of the observed response values in the training-fold data. (since R2023b)
Examples
Predict Responses from Cross-Validated Kernel Regression Models
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
0.8869
0.7744
0.8915
0.8040
0.8870
Input Arguments
CVMdl
— Cross-validated kernel regression model
RegressionPartitionedKernel
model object
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).
prediction
— Predicted response value to use for observations with missing predictor values
"median"
(default) | "mean"
| numeric scalar
Since R2023b
Predicted response value to use for observations with missing predictor values,
specified as "median"
, "mean"
, or a numeric
scalar.
Value | Description |
---|---|
"median" | kfoldPredict 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" | kfoldPredict uses the mean of the observed response
values in the training-fold data as the predicted response value for
observations with missing predictor values. |
Numeric scalar | kfoldPredict uses this value as the predicted response
value for observations with missing predictor values. |
Example: "mean"
Example: NaN
Data Types: single
| double
| char
| string
Output Arguments
YHat
— Cross-validated predicted responses
numeric vector
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).
Version History
Introduced in R2018bR2023b: Specify predicted response value to use for observations with missing predictor values
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 the
PredictionForMissingValue
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.
See Also
fitrkernel
| RegressionKernel
| RegressionPartitionedKernel
| kfoldLoss
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)