我正在使用fitrsvm进行默认,交叉验证和KFold验证。
%%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中是否有任何内置函数(如丢失或KfoldLoss)?或者我需要将它们作为函数实现吗?
答案 0 :(得分:0)
这里我实现了方向对称(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
虽然这对我来说很好,但如果有人帮我改进线路数量或提高效率,我会很感激。