resubLoss

Class: RegressionGP

Resubstitution loss for a trained Gaussian process regression model

Syntax

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

Description

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.

Examples

expand all

This example uses "Housing" data set [1] from the UCI machine learning archive [2] described in http://archive.ics.uci.edu/ml/datasets/Housing. Download the data and save it in your current directory as a data file named housing.data.

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.

load('housing.data');
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',...
'FitMethod','sr','PredictMethod','fic');

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
ylabel('y');
legend('Actual response','Predicted response','Location','SouthWest');
axis([0 510 -10 55]);
hold off

Compute the resubstitution loss.

L = resubLoss(gprMdl)
L =

    4.8478

Manually compute the regression loss.

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

    4.8478

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

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

Alternatives

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

References

[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. http://archive.ics.uci.edu/ml.

Introduced in R2015b