Main Content


Predict response of Gaussian process regression model


ypred = predict(gprMdl,Xnew)
[ypred,ysd] = predict(gprMdl,Xnew)
[ypred,ysd,yint] = predict(gprMdl,Xnew)
[ypred,ysd,yint] = predict(gprMdl,Xnew,Name,Value)


ypred = predict(gprMdl,Xnew) returns the predicted responses ypred for the full or compact Gaussian process regression (GPR) model, gprMdl, and the predictor values in Xnew.

[ypred,ysd] = predict(gprMdl,Xnew) also returns the estimated standard deviations for the new responses at the predictor values in Xnew from a trained GPR model.

[ypred,ysd,yint] = predict(gprMdl,Xnew) also returns the 95% prediction intervals, yint, for the true responses corresponding to each row of Xnew.

[ypred,ysd,yint] = predict(gprMdl,Xnew,Name,Value) also returns the prediction intervals with additional options specified by one or more Name,Value pair arguments. For example, you can specify the confidence level of the prediction interval.

Input Arguments

expand all

Gaussian process regression model, specified as a RegressionGP (full) or CompactRegressionGP (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 train gprMdl.

If you trained gprMdl on a matrix, then Xnew must be a numeric matrix with d columns.

Data Types: single | double | table

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Significance level for the prediction intervals, specified as the comma-separated pair consisting of 'Alpha' and a scalar value in the range from 0 to 1.

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

Data Types: single | double

Output Arguments

expand all

Predicted response values, returned as an n-by-1 vector.

Estimated standard deviation of the new response values, returned as an n-by-1 vector , where ysd(i), i = 1, 2, ..., n, contains the estimated standard deviation of the new response corresponding to the predictor values at the ith row of Xnew from the trained GPR model.

Prediction intervals for the true response values corresponding to each row of Xnew, returned as an n-by-2 matrix. The first column of yint contains the lower limits and the second column contains the upper limits of the prediction intervals.


expand 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.5*rand(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',...

Compute the predictions.

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

Plot the data along with the predictions and prediction intervals.

hold on

Figure contains an axes. The axes contains 4 objects of type line.

Load the sample data and store in a table.

load fisheriris
tbl = table(meas(:,1),meas(:,2),meas(:,3),meas(:,4),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.

hold on;
legend('True response','GPR predictions',...
'Lower prediction limit','Upper prediction limit',...

Figure contains an axes. The axes contains 4 objects of type line. 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 8 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',...

Predict the responses for test data.

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

Plot the test response along with the predictions.

hold on;
legend('Actual response','GPR predictions',...
'95% lower','95% upper','Location','Best');
hold off

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


  • You can choose the prediction method while training the GPR model using the PredictMethod name-value pair argument in fitrgp. The default prediction method is 'exact' for n ≤ 10000, where n is the number of observations in the training data, and 'bcd' (block coordinate descent), otherwise.

  • Computation of standard deviations, ysd, and prediction intervals, yint, is not supported when PredictMethod is 'bcd'.

  • If gprMdl is a CompactRegressionGP object, you cannot compute standard deviations, ysd, or prediction intervals, yint, for PredictMethod equal to 'sr' or 'fic'. To compute ysd and yint for PredictMethod equal to 'sr' or 'fic', use the full regression (RegressionGP) object.


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

Extended Capabilities

Introduced in R2015b