Documentation

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 moreName,Valuepair arguments. For example, you can specify a custom loss function or the observation weights.

Input Arguments

expand all

Gaussian process regression model, specified as aRegressionGPobject.

Name-Value Pair Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside single quotes (' '). You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

expand all

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, sayfun,resubLosscalls it as :fun(Y,Ypred,W), whereY,Ypred, andWare numeric vectors of lengthn, andnis the number of observations in the training data.Yis the observed response,Ypredis the predicted response, andWis the observation weights.

Example:'lossfun',Fctcalls the loss functionFct.

Data Types:char|function_handle

Observation weights, specified as ann1vector, wherenis 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 =住房(:,1:13);y =住房(:,结束);

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 valuesholdon; plot(ypred,'b--');% Plot predicted response valuesylabel('y');legend('Actual response','Predicted response','Location','SouthWest');axis([0 510 -10 55]); holdoff

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 atable.

loadfisheriristbl = 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, useloss.

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

Was this topic helpful?