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

9 ビュー (過去 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 Center および File ExchangeGaussian Process Regression についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by