Validate gaussian process regression model with leave-one-out cross validation

8 次查看(过去 30 天)
Dear all,
I have a dataset with:
X = Torque (the input variable)
Y1 = Response 1
Y2 = Response 2
Y3 = Response 3
I want to use the method of leave-one-out cross-validation (LOOCV) to validate the gaussian process regression model. Then, I want to asses the quality of the model by using the root mean squared error (RMSE) and coefficient of determination (R2). How can I do this?

回答(1 个)

Paras Gupta
Paras Gupta 2024-5-20
编辑:Paras Gupta 2024-5-20
Hi Tessa,
To validate and assess a Gaussian Process Regression (GPR) model using the LOOCV Method, you can iteratively compute the RMSE and R2 values for each of the respone variables. The following code illustrates one way to achieve the same for the response variable 'Y1':
load('dataset.mat');
Y = Y1;
n = length(Y); % Number of observations
predictions = zeros(n, 1); % Preallocate predictions vector
for i = 1:n
% Indices for the training set (all data points except the ith)
trainIdx = [1:i-1, i+1:n];
% Create a Gaussian process regression model
gprMdl = fitrgp(X(trainIdx, :), Y(trainIdx), 'Basis', 'constant', 'FitMethod', ...
'exact', 'PredictMethod', 'exact');
% Predict the left-out observation
predictions(i) = predict(gprMdl, X(i, :));
end
% Calculate RMSE
rmse = sqrt(mean((Y - predictions).^2));
% Calculate R^2
SStot = sum((Y - mean(Y)).^2);
SSres = sum((Y - predictions).^2);
rSquared = 1 - (SSres / SStot);
fprintf('RMSE: %f\n', rmse);
RMSE: 0.010725
fprintf('R^2: %f\n', rSquared);
R^2: 0.991260
You can refer to the following documentations for more information on the functions used in the code above:
Hope this answers your query.

类别

Help CenterFile Exchange 中查找有关 Gaussian Process Regression 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by