How to get RMSE, R-squared, and p-values from fitrgp?
13 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Anurag
on 23 Oct 2023
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
0 Comments
See Also
Categories
Find more on Gaussian Process Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!