-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevaluate_preds.m
28 lines (28 loc) · 1.06 KB
/
evaluate_preds.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
function EVAL = evaluate_preds(ACTUAL,PREDICTED)
% This fucntion evaluates the performance of a SSVDD model by
% calculating the common performance measures: Accuracy, tp_rate,
% Precision, F-Measure, G-mean.
% Input: ACTUAL = Column matrix with actual class labels of the training
% examples
% PREDICTED = Column matrix with predicted class labels by the
% classification model
% Output: EVAL = Row matrix with all the performance measures
idx = (ACTUAL()==1);
p = length(ACTUAL(idx));
n = length(ACTUAL(~idx));
N = p+n;
tp = sum(ACTUAL(idx)==PREDICTED(idx));
tn = sum(ACTUAL(~idx)==PREDICTED(~idx));
fp = n-tn;
tp_rate = tp/p;
tn_rate = tn/n;
accuracy = (tp+tn)/N;
precision = tp/(tp+fp);
precision(isnan(precision))=0;
recall = tp_rate;
f_measure = 2*((precision*recall)/(precision + recall));
f_measure(isnan(f_measure))=0;
tp_rate(isnan(tp_rate))=0; tp_rate(isnan(tp_rate))=0; tn_rate(isnan(tn_rate))=0;
gmean = sqrt(tp_rate*tn_rate);
EVAL = [accuracy tp_rate tn_rate precision f_measure gmean];
end