Main Content


Class: RegressionGP

Resubstitution loss for a trained Gaussian process regression model


L = resubLoss(gprMdl)
L = resubLoss(gprMdl,Name,Value)


L = resubLoss(gprMdl) returns the resubstitution mean squared error for the Gaussian process regression (GPR) model, gprMdl.

L = resubLoss(gprMdl,Name,Value) returns the resubstitution loss for the GPR model, gprMdl, with additional options specified by one or more Name,Value pair arguments. For example, you can specify a custom loss function or the observation weights.

Input Arguments

expand all

Gaussian process regression model, specified as a RegressionGP object.

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.

Loss function for the trained GPR model, specified as 'mse' or a function handle. 'mse' stands for the mean squared error.

If you pass a function handle, say fun, resubLoss calls it as : fun(Y,Ypred,W), where Y, Ypred, and W are numeric vectors of length n, and n is the number of observations in the training data. Y is the observed response, Ypred is the predicted response, and W is the observation weights.

Example: 'lossfun',Fct calls the loss function Fct.

Data Types: char | string | function_handle

Observation weights, specified as an n-by-1 vector, where n is the number of observations in the training data. By default, weight of each observation is 1.

Data Types: double | single

Output Arguments

expand all

Resubstitution error for the GPR model, returned as a scalar value.


expand all

This example uses "Housing" data set [1] from the UCI machine learning archive [2] described in Download the data and save it in your current directory as a data file named

The dataset has 506 observations. The first 13 columns contain the predictor values and the last column contains the response values. The goal is to predict the median value of owner-occupied homes in the Boston suburb area as a function of 13 predictors.

Load the data and define the response vector and predictor matrix.

X = housing(:,1:13);
y = housing(:,end);

Fit a GPR model using subset of regressors ('sr') approximation method with Matern 3/2 ('Matern32') kernel function. Predict using the fully independent conditional ('fic') method.

gprMdl = fitrgp(X,y,'KernelFunction','Matern32',...

Compute the resubstitution predictions.

ypred = resubPredict(gprMdl);

Plot the predicted response values along with the actual response values.

plot(y,'r'); % Plot original response values
hold on;
plot(ypred,'b--'); % Plot predicted response values
legend('Actual response','Predicted response','Location','SouthWest');
axis([0 510 -10 55]);
hold off

Compute the resubstitution loss.

L = resubLoss(gprMdl)
L =


Manually compute the regression loss.

n = length(y);
L = (y-ypred)'*(y-ypred)/n
L =


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');

Predict the responses using the trained model.

ypred = predict(mdl,tbl);

Compute the mean absolute error.

n = height(tbl);
y = tbl.meas1;
fun = @(y,ypred,w) sum(abs(y-ypred))/n;
L = resubLoss(mdl,'lossfun',fun)
L = 0.2345


To compute the regression error for new data, use loss.


[1] Harrison, D. and D.L., Rubinfeld. "Hedonic prices and the demand for clean air." J. Environ. Economics & Management. Vol.5, 1978, pp. 81-102.

[2] Lichman, M. UCI Machine Learning Repository, Irvine, CA: University of California, School of Information and Computer Science, 2013.

Introduced in R2015b