1 function [classificationRate, prec, recall, f1s] =
classificationPrec(labels, groundTruth, nbClasses)
2 %Mohammad Soleymani cvml Lab., University of Geneva, 2009
3 %mohammad.soleymani@unige.ch
4 %
function [classificationRate, prec,f1s,recall,accuracy] =
6 %This
function gives you precisions, recalls, f1 scores
for each class
7 %separately and classification rate overally
8 %it is assumed that the labels (estimated and correct) are numeric and they
9 %start by 1 and continues. e.x.
for binary classification labels should be
12 % labels: the esimated labels
13 % groundTruth: ground truth (correct labels)
14 % nbClasses: number of classes
16 %classificationRate : the number of correctly classified samples divided by
18 % prec: precisions
for each class
19 % recall: recall
for each class
20 % f1s: f1 score
for each class
23 groundTruth = groundTruth(:);
25 nbClasses = max(groundTruth);
27 prec = zeros(1, nbClasses);
28 recall = zeros(1, nbClasses);
30 TP = sum(labels==i & groundTruth==i);
31 FP = sum(labels==i & groundTruth~=i);
32 FN = sum(labels~=i & groundTruth==i);
34 recall(i) = TP/(TP+FN);
37 f1s = 2*prec.*recall./(prec+recall);
38 classificationRate = sum(labels==groundTruth)/length(labels);