【问题标题】:How to calculate MAPE and DS in MATLAB如何在 MATLAB 中计算 MAPE 和 DS
【发布时间】:2017-02-19 02:33:02
【问题描述】:

我正在使用带有默认、交叉验证和 KFold 验证的 fitrsvm。

%%In sample validation.
rng default ;
mdl = fitrsvm(X,Y, 'Standardize',true);
loss =  resubLoss(mdl)
%% out of sample validation with 80% traning and 20% validation    
CVmdl = crossval(mdl,'Holdout',0.2);
CVloss = kfoldLoss(CVmdl)
%% 10Fold Cross Validation Model
KFmdl = crossval(mdl);
KFloss = kfoldLoss(KFmdl)

我需要计算这些模型的 MAPE 和方向对称性 (DS)。 Matlab 中是否有任何内置函数(如 loss 或 KfoldLoss)?还是我需要将这些实现为功能?

【问题讨论】:

  • 你能告诉我停机的原因,以便我以后避免它吗?

标签: matlab regression svm


【解决方案1】:

在这里,我将方向对称 (DS) 和平均绝对百分比误差 (MAPE) 都实现为函数

function mape( Y, Ypredict, indxtest)
smape = 0;

    if isempty(indxtest)
        for i = 1 :length(Y)
           smape = smape + (abs((Ypredict(i) - Y(i))) / Y(i));
        end
    else
        j = find(indxtest); 
        for i = 1 :length(j)
           smape = smape + (abs((Ypredict(i) - Y(j(i)))) / Y((j(i))));
        end   
    end

mape = smape * 100/length(Y)
end
-------------------------------------------------------
function ds( Y, Ypredict, indxtest)
sds = 0;
if isempty(indxtest)
   for i = 2 :length(Y)
      if (((Y(i)-Y(i-1))*(Ypredict(i)-Ypredict(i-1))) > 0)
         sds = sds + 1;
      end
   end
else
   j = find(indxtest);   
   for i = 2 :length(j)
       if (((Y(j(i))-Y(j(i-1)))*(Ypredict((i))-Ypredict(i-1))) > 0)
           sds = sds + 1;
       end
   end
end
ds = sds * 100/length(j)
end

虽然这对我来说很好,但如果有人帮助我改进它,或者减少行数或提高效率,我将不胜感激。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-18
    • 2012-02-24
    • 1970-01-01
    • 2017-09-10
    • 1970-01-01
    • 2016-09-02
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多