% true values y_true = [1, 2, 3, 4, 5]; % predicted values y_pred = [1.5, 2.5, 2.8, 3.7, 5.2]; % calculate rmse rmse = sqrt(mean((y_true - y_pred).^2)) % output the rmse disp(rmse) in matlab

To calculate the % of true values between two arrays, you can use the following code in MATLAB:

main.m
y_true = [1,2,3,4,5];
y_pred = [1.5,2.5,2.8,3.7,5.2];

% calculate rmse
rmse = sqrt(mean((y_true - y_pred).^2));

% calculate % true values
percent_true = sum(y_pred == y_true) / length(y_true) * 100;

% output the rmse and % true values
disp(['RMSE: ', num2str(rmse)])
disp(['% True Values: ', num2str(percent_true)])
319 chars
13 lines

This code first calculates the RMSE between the y_true and y_pred arrays using the formula sqrt(mean((y_true - y_pred).^2)).

Then, the code calculates the % of true values by counting the number of times y_pred is exactly equal to y_true and dividing by the length of the arrays, multiplied by 100 to get a percentage.

The code outputs the RMSE and % true values using the disp function.

related categories

gistlibby LogSnag