【发布时间】:2017-01-13 00:24:05
【问题描述】:
我有两个时间序列。一种是预测的,一种是原创的。为了计算预测精度,我想计算 MAPE(平均绝对百分比误差)。
平均绝对百分比误差 (MAPE),也称为平均绝对百分比偏差 (MAPD),是统计预测方法(例如趋势估计)的预测准确性的度量。它通常以百分比表示准确率,并由以下公式定义:
我在 MATLAB 中这样做如下:
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
但是当 Actual 系列中有 0 时,函数在结果中返回 -INF。
我想排除那个 0 和其他序列中的相应值并计算 MAPE 值。
【问题讨论】: