-
Notifications
You must be signed in to change notification settings - Fork 3
/
Evaluate.m
44 lines (32 loc) · 1.22 KB
/
Evaluate.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
% This fucntion evaluates the performance of a classification model by
% calculating the common performance measures: Accuracy, Sensitivity,
% Specificity, Precision, Recall, 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
function EVAL = Evaluate(ACTUAL,PREDICTED)
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;
fn = p-tp;
tp_rate = tp/p;
tn_rate = tn/n;
accuracy = (tp+tn)/N;
sensitivity = tp_rate;
specificity = tn_rate;
precision = tp/(tp+fp);
precision(isnan(precision))=0;
recall = sensitivity;
f_measure = 2*((precision*recall)/(precision + recall));
f_measure(isnan(f_measure))=0;
sensitivity(isnan(sensitivity))=0; % to avoind NANs
tp_rate(isnan(tp_rate))=0;
tn_rate(isnan(tn_rate))=0;
gmean = sqrt(tp_rate*tn_rate);
avg_senspec=((sensitivity+specificity)/2);
EVAL = [accuracy sensitivity specificity precision recall f_measure gmean avg_senspec];
end