【问题标题】:exclude 0 in MAPE calculation in matlab在matlab的MAPE计算中排除0
【发布时间】: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 值。

【问题讨论】:

    标签: matlab math


    【解决方案1】:

    您可以在 nanmean 中使用逻辑索引来排除 testY 中的零值

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

    【讨论】:

      猜你喜欢
      • 2017-02-19
      • 2018-05-18
      • 1970-01-01
      • 2018-04-02
      • 1970-01-01
      • 2020-02-22
      • 2012-02-24
      • 2017-09-10
      • 1970-01-01
      相关资源
      最近更新 更多