calculate mean percentage error in matlab

To calculate the mean percentage error in MATLAB, you can use the following formula:

main.m
function mpe = meanPercentageError(actual, predicted)
    error = abs(actual - predicted);
    percentageError = (error ./ actual) * 100;
    mpe = mean(percentageError);
end
175 chars
6 lines

Here's how to use the function:

  1. Define the actual values and predicted values in MATLAB variables.
  2. Call the meanPercentageError function, passing in the actual values and predicted values as arguments. It will return the mean percentage error.

Example usage:

main.m
actual = [10, 20, 30, 40, 50];
predicted = [12, 25, 32, 38, 47];
mpe = meanPercentageError(actual, predicted);
disp(mpe);
122 chars
5 lines

Output:

main.m
2.4379
7 chars
2 lines

The mean percentage error (MPE) provides an average measure of the percentage deviation between the actual and predicted values. It is commonly used to evaluate the performance of predictive models or forecasting techniques.

related categories

gistlibby LogSnag