-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_auc.m
37 lines (35 loc) · 946 Bytes
/
calculate_auc.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
function AUC=calculate_auc(targets,predicts)
%calculate_auc calculates the area under the Precission/recall curve
%
% AUC = calculate_auc(targets,predicts)
%
% INPUT:
% targets: actual labels
% predicts: prediction scores
%
% OUTPUT
% AUC: area under the ROC curve
%
% Borrowed from code of:
% Twan van Laarhoven, Sander B. Nabuurs, Elena Marchiori,
% (2011) Gaussian interaction profile kernels for predicting drug–target interaction
% http://cs.ru.nl/~tvanlaarhoven/drugtarget2011/
if nargin > 1
[~,i] = sort(predicts,'descend');
targets = targets(i);
end
%for i=1:n
% if targets(i)
% goods = goods + 1
% else
% auc = auc + goods;
% end
%end
cumsums = cumsum(targets);
AUC = sum(cumsums(~targets));
pos = sum(targets);
neg = sum(~targets);
if pos == 0, warning('Calculate auc: no positive targets'); end
if neg == 0, warning('Calculate auc: no negative targets'); end
AUC = AUC / (pos * neg + eps);
end