predict - Predict response of Gaussian process regression model - MATLAB (original) (raw)

Predict response of Gaussian process regression model

Syntax

Description

[ypred](#buto5ym-ypred) = predict([gprMdl](#buto5ym-gprMdl),[Xnew](#buto5ym-Xnew)) returns the predicted responses ypred for the Gaussian process regression (GPR) model gprMdl and the predictor values inXnew.

[[ypred](#buto5ym-ypred),[ysd](#buto5ym-ysd),[yint](#buto5ym-yint)] = predict([gprMdl](#buto5ym-gprMdl),[Xnew](#buto5ym-Xnew)) also returns the standard deviations ysd and 95% prediction intervalsyint of the response variable, evaluated at each observation in Xnew using the trained GPR model.

example

[[ypred](#buto5ym-ypred),[ysd](#buto5ym-ysd),[yint](#buto5ym-yint)] = predict([gprMdl](#buto5ym-gprMdl),[Xnew](#buto5ym-Xnew),[Name,Value](#namevaluepairarguments)) specifies additional options using one or more name-value arguments. For example, specify the significance level for the confidence level of the prediction intervalsyint.

example

Examples

collapse all

Generate the sample data.

n = 10000; rng(1) % For reproducibility x = linspace(0.5,2.5,n)'; y = sin(10*pi.*x) ./ (2.x)+(x-1).^4 + 1.5rand(n,1);

Fit a GPR model using the Matern 3/2 kernel function with separate length scale for each predictor and an active set size of 100. Use the subset of regressors approximation method for parameter estimation and fully independent conditional method for prediction.

gprMdl = fitrgp(x,y,'KernelFunction','ardmatern32', ... 'ActiveSetSize',100,'FitMethod','sr','PredictMethod','fic');

Compute the predictions.

[ypred,~,yci] = predict(gprMdl,x);

Plot the data along with the predictions and prediction intervals.

plot(x,y,'r.') hold on plot(x,ypred,'b-') plot(x,yci(:,1),'k--') plot(x,yci(:,2),'k--') xlabel('x') ylabel('y') legend('True responses','GPR predictions', ... 'Prediction interval limits','Location','best')

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent True responses, GPR predictions, Prediction interval limits.

Load the sample data and store in a table.

load fisheriris tbl = table(meas(:,1),meas(:,2),meas(:,3),meas(:,4),species,... 'VariableNames',{'meas1','meas2','meas3','meas4','species'});

Fit a GPR model using the first measurement as the response and the other variables as the predictors.

mdl = fitrgp(tbl,'meas1');

Compute the predictions and the 99% confidence intervals.

[ypred,~,yci] = predict(mdl,tbl,'Alpha',0.01);

Plot the true response and the predictions along with the prediction intervals.

figure(); plot(mdl.Y,'r.'); hold on; plot(ypred); plot(yci(:,1),'k:'); plot(yci(:,2),'k:'); legend('True response','GPR predictions',... 'Lower prediction limit','Upper prediction limit',... 'Location','Best');

Figure contains an axes object. The axes object contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent True response, GPR predictions, Lower prediction limit, Upper prediction limit.

Load the sample data.

The data contains training and test data. There are 500 observations in training data and 100 observations in test data. The data has 6 predictor variables. This is simulated data.

Fit a GPR model using the squared exponential kernel function with a separate length scale for each predictor. Standardize predictors in the training data. Use the exact fitting and prediction methods.

gprMdl = fitrgp(Xtrain,ytrain,'Basis','constant',... 'FitMethod','exact','PredictMethod','exact',... 'KernelFunction','ardsquaredexponential','Standardize',1);

Predict the responses for test data.

[ytestpred,~,ytestci] = predict(gprMdl,Xtest);

Plot the test response along with the predictions.

figure; plot(ytest,'r'); hold on; plot(ytestpred,'b'); plot(ytestci(:,1),'k:'); plot(ytestci(:,2),'k:'); legend('Actual response','GPR predictions',... '95% lower','95% upper','Location','Best'); hold off

Figure contains an axes object. The axes object contains 4 objects of type line. These objects represent Actual response, GPR predictions, 95% lower, 95% upper.

Input Arguments

collapse all

Gaussian process regression model, specified as aRegressionGP (full) orCompactRegressionGP (compact) object.

New values for the predictors that fitrgp uses in training the GPR model, specified as a table or an_m_-by-d matrix.m is the number of observations and_d_ is the number of predictor variables in the training data.

If you trained gprMdl on a table, then Xnew must be a table that contains all the predictor variables used to traingprMdl.

If you trained gprMdl on a matrix, thenXnew must be a numeric matrix with_d_ columns.

Data Types: single | double | table

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: predict(grpMdl,Xnew,"Alpha",0.1) specifies the confidence level of the prediction intervals to be 90%.

Significance level for the confidence level of the prediction intervals yint, specified as a numeric scalar in the range [0,1]. The confidence level ofyint is equal to100(1 – Alpha)%.

Example: 'Alpha',0.01 specifies to return 99% prediction intervals.

Data Types: single | double

Since R2023b

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

Value Description
"median" predict uses the median of the observed response values in the training data as the predicted response value for observations with missing predictor values.
"mean" predict uses the mean of the observed response values in the training data as the predicted response value for observations with missing predictor values.
Numeric scalar predict uses this value as the predicted response value for observations with missing predictor values.

Example: PredictionForMissingValue="mean"

Example: PredictionForMissingValue=NaN

Data Types: single | double | char | string

Output Arguments

collapse all

Predicted responses, returned as a column vector of length_n_, where n is the number of observations in the predictor data Xnew.

Standard deviations of the response variable, evaluated at each observation in the predictor data Xnew, returned as a column vector of length n, where n is the number of observations in Xnew. Theith element ysd(i) contains the standard deviation of the ith response for theith observation`Xnew`(i,:), estimated using the trained GPR model gprMdl.

Prediction intervals of the response variable, evaluated at each observation in the predictor data Xnew, returned as an_n_-by-2 matrix, where n is the number of observations in Xnew. Theith row yint(i,:) contains the100(1 – [Alpha](#buto5ym-Alpha))% prediction interval of the ith response for theith observation`Xnew`(i,:). TheAlpha value is the probability that the prediction interval does not contain the true response value for`Xnew`(i,:). The first column of yint contains the lower limits of the prediction intervals, and the second column contains the upper limits.

Tips

Alternatives

You can use resubPredict to compute the predicted responses for the trained GPR model at the observations in the training data.

To integrate the prediction of a Gaussian process regression model into Simulink®, you can use the RegressionGP Predict block in the Statistics and Machine Learning Toolbox™ library or a MATLAB® Function block with the predict function. For examples, see Predict Responses Using RegressionGP Predict Block and Predict Class Labels Using MATLAB Function Block.

When deciding which approach to use, consider the following:

Extended Capabilities

expand all

Thepredict function fully supports tall arrays. For more information, see Tall Arrays.

Usage notes and limitations:

For more information, see Introduction to Code Generation.

Version History

Introduced in R2015b

expand all

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.