how to calculate mape

8 views (last 30 days)
andrew moisidi
andrew moisidi on 31 May 2021
Answered: Steven Lord on 20 Nov 2024 at 7:00
hey guys i want help how i can calculate mape and how to calculate which calculates the linear product for the product with price values f
function [a,b,MAPE] = getLinearModel(f)
n = length(f);
A = zeros(1,length(f)-1);
b = zeros(1,length(f)-1);
for i=2:n
if f(i-1) ~= 0
A(i-1) = f(i)/f(i-1);
else
A(i-1) = 1;
end
end
a = median(A); %more robust than mean function
for i=1:length(f)-1
b (i) = f(i)/a*i+b;
end
g0 = median(b);%more robust than mean function
  2 Comments
Image Analyst
Image Analyst on 31 May 2021
What is mape? Do you have some definition or formula for it? You never assigned the output variable MAPE in your function so it can't return it.
What does this have to do with image analysis (you tagged it as such)?
What is f? Evidently a vector, not an image.
DGM
DGM on 31 May 2021
To calculate MAPE, you'd have to know what any of these variables mean conceptually. Single-letter nondescriptive variable names cannot communicate that information. You'll have to figure that out because you're the only one who can know what your code means without an impractical amount of guessing.
I don't know what this has to do with images either.

Sign in to comment.

Answers (2)

Omega
Omega on 20 Nov 2024 at 6:06
Hi,
MAPE (Mean Absolute Percentage Error) is calculated using the formula:
where () are the actual values, and ( ) are the predicted values.
It's difficult to understand what your variables mean because of the acronym names. You can use the following formula by plugging in the values for y_true and y_pred:
% Calculate MAPE
mape = mean(abs((y_true - y_pred) ./ y_true)) * 100;
fprintf('Mean Absolute Percentage Error (MAPE): %.2f%%\n', mape);
Hope it helps!

Steven Lord
Steven Lord on 20 Nov 2024 at 7:00
The mape function was added to MATLAB in release R2022b.

Categories

Find more on Financial Data 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!