-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdd_f1.m
More file actions
executable file
·69 lines (56 loc) · 1.3 KB
/
dd_f1.m
File metadata and controls
executable file
·69 lines (56 loc) · 1.3 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
%DD_F1 compute the F1 score
%
% E = DD_F1(X,W)
% E = DD_F1(X*W)
% E = X*W*DD_F1
%
% INPUT
% X One-class dataset
% W One-class classifier
%
% OUTPUT
% E F1 performance
%
% DESCRIPTION
% Compute the F1 score of a dataset, defined as:
% 2*precision*recall
% F1 = ------------------
% precision + recall
%
% SEE ALSO
% dd_error, dd_roc
% Copyright: D.M.J. Tax, D.M.J.Tax@prtools.org
% Faculty EWI, Delft University of Technology
% P.O. Box 5031, 2600 GA Delft, The Netherlands
function e = dd_f1(x,w)
% Do it the same as testc:
% When no input arguments are given, we just return an empty mapping:
if nargin==0
e = prmapping(mfilename,'fixed');
e = setname(e,'F1');
return
elseif nargin == 1
% Now we are doing the actual work, our input is a mapped dataset:
% get the precision and recall:
[dummy,f] = dd_error(x);
% do some checks:
if ~isfinite(f(1))
warning('dd_tools:NonfiniteOutputs',...
'The precision is not finite (all data is classified as outlier)');
e = nan;
return;
end
if ~isfinite(f(2))
warning('dd_tools:NonfiniteOutputs',...
'The recall is not finite (no target data present?)');
e = nan;
return
end
% and compute F1:
e = (2*f(1)*f(2))/(f(1)+f(2));
else
ismapping(w);
istrained(w);
e = feval(mfilename,x*w);
end
return