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

조회 수: 8 (최근 30일)
Tessa Kol
Tessa Kol 2021년 5월 18일
편집: Paras Gupta 2024년 5월 20일
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