首页 > 解决方案 > 如何在 Matlab 中计算“比较”功能

问题描述

我正在研究均方根误差 (RMSE) 和归一化均方根误差 (NRMSE)。

根据维基百科的文章并根据Matlab的功能

为什么 Wikipedia 手动 NRMSE 和 MATLAB 代码 NRMSE 之间的 NRMSE 值不同compare

你能教我如何用compare数学方法计算函数吗?

例如,我做了如下。维基百科的方法:

Vt = 1:11;
V1 = [11.5 7.6 6.7 8.3 7.7 7.4 6.5 5.6 6.6 11.2 11.9]; % obseved data
V2 = [11.9 10.8 8.3 9.6 11.4 10.2 12.4 9.6 8.3 8 9]; % estimationd data
RMSE = sqrt(mean((V1-V2).^2)); % RMSE = 3.14107
NRMSE = RMSE/(max(V2)-min(V2)) % NRMSE = 0.71

MATLAB的比较内部函数:

% to use compare
VV1 = iddata(V1', Vt');
VV2 = iddata(V2', Vt');
compare(VV1,VV2) % -48.46%

标签: matlabmean-square-error

解决方案


根据compare文档,Matlab 对 NRMSE 的估计与您的不同。

您需要知道计算 RMSE 和 NRMSE 的方法有很多种。从您在Root-mean-square deviation上链接的 Wikipedia 文章中:

文献中没有一致的标准化方法

你选择了一种方式,而 Matlab 有另一种方式。

合身

所以如果你想匹配 Matlab 的结果,你应该这样做:

NRMSE = 100*(1 - norm(V1-V2)/norm(V1-mean(V1)))
[y,fit,x0] =compare(VV1,VV2); fit

这返回

 NRMSE =
  -48.4595

 fit =
  -48.4595

推荐阅读