필터 지우기
필터 지우기

How to get RMSE, R-squared, and p-values from fitrgp?

조회 수: 17 (최근 30일)
Tobenna Uzuegbunam
Tobenna Uzuegbunam 2022년 4월 7일
답변: Anurag 2023년 10월 23일
I have trained a model on a table including dependent variable 'Arm' and 6 independent variables 'duration' + 'heading' + 'speed' + 'cur_speed' + 'tidalrange' + 'Hs', using the code below.
How to get the RMSE, R-squared value, and p-values from the model?
I have tried using 'gprMdl.Rsquared.Ordinary' and 'gprMdl.Rsquared.Adjusted' but it doesn't seem to work
gprMdl = fitrgp(tableTest,'Arms~duration+heading+speed+cur_speed+tidalrange+Hs',...
'KernelFunction','squaredexponential','FitMethod','exact','PredictMethod',...
'exact','Standardize',1)
yPredict = predict(gprMdl,tableTest) % Create model predictions
yActual = tableTest.Arms % Observed data
residuals = yActual - yPredict % Calculate residuals

답변 (1개)

Anurag
Anurag 2023년 10월 23일
Hi Tobenna,
I understand that being unable to use the inbuilt metrics you want to find a way to calculate RMSE, R-squared and p-values from your code. Refer to the following code for doing the same:
% Calculate RMSE (Root Mean Square Error)
RMSE = sqrt(mean(residuals.^2));
% Calculate R-squared
SSR = sum((yPredict - mean(yActual)).^2); % Regression sum of squares
SST = sum((yActual - mean(yActual)).^2); % Total sum of squares
R2 = SSR / SST;
Lastly, for p-values, you would typically need to use linear regression models or other models that provide statistical tests for variable significance. GPR doesn't inherently provide p-values because it's not a linear regression model.
Hope this helped,
Regards,
Anurag

카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by