0
votes

I have two time series. one is predicted and one is original. To calculate prediction accuracy, i want to calculate MAPE(mean absolute percentage error).

The mean absolute percentage error (MAPE), also known as mean absolute percentage deviation (MAPD), is a measure of prediction accuracy of a forecasting method in statistics, for example in trend estimation. It usually expresses accuracy as a percentage, and is defined by the formula:

formula for MAPE calculation

I am doing this in MATLAB as follows:

function m = mape(testY, pred)
% Compute mean absolute percent error
%
% m = mape(actual, pred)
%
% actual is a column vector of actual values
% pred is a matrix of predictions (one per column)
%
% m is the mean absolute percent error (ignoring NaNs) for each column of
% pred. 


err = abs(bsxfun(@minus, pred, testY));
pcterr = bsxfun(@rdivide, err, testY);
m = nanmean(pcterr,1);
end

But when there is a 0 in Actual series, function returns -INF in result.

I want to exclude that 0 and corresponding value in other sequence and calculate MAPE value.

1

1 Answers

1
votes

You can use logical indexing in the nanmean to exclude the zero values in testY

m = nanmean(pcterr(testY~=0),1);