-
Notifications
You must be signed in to change notification settings - Fork 8
/
mABSERROR.m
56 lines (49 loc) · 1.65 KB
/
mABSERROR.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [RESULT] = mABSERROR(DATA, NORMALIZER)
% Calculate mean absolute error with different normalization options
%
% DATA is a numeric matrix where each row is one object, the first column
% contains the test results (predictions), and the second column contains
% the criterion results (trusted labels). Note that this function is most
% appropriate when the data being compared is dimensional.
%
% NORMALIZER is an optional parameter that specifies what the mean
% absolute error value should be divided by (default = 1). Valid options
% include 'range', 'mean', 'std', and any real number. If 'range',
% 'mean', or 'std' is chosen, the values are calculated from the
% observed criterion results (i.e., the second column of DATA).
%
% RESULT is a scalar containing the mean absolute error if NORMALIZER
% was set to 1, or the normalized mean absolute error otherwise.
%
% Example usage: mABSERROR([preds, labels])
% Example usage: mABSERROR([preds, labels], 'range')
% Example usage: mABSERROR(readydata, 50.23)
%
% (c) Jeffrey M. Girard, 2018
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~isnumeric(DATA)
disp('DATA must be a numeric matrix');
RESULT = NaN;
return;
end
if size(DATA, 2) ~= 2
disp('DATA must have 2 columns');
RESULT = NaN;
return;
end
if nargin < 2
NORMALIZER = 1;
end
TEST = DATA(:, 1);
CRIT = DATA(:, 2);
if strcmpi(NORMALIZER, 'range')
NORMALIZER = range(CRIT);
elseif strcmpi(NORMALIZER, 'mean')
NORMALIZER = nanmean(CRIT);
elseif strcmpi(NORMALIZER, 'std')
NORMALIZER = nanstd(CRIT);
end
MAE = nanmean(abs(CRIT - TEST));
RESULT = MAE / NORMALIZER;
end