TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
classificationPrec.m
Go to the documentation of this file.
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] =
5 %classificationPrec(labels, groundTruth, nbClasses)
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
10 %1 and 2
11 %inputs:
12 % labels: the esimated labels
13 % groundTruth: ground truth (correct labels)
14 % nbClasses: number of classes
15 %outputs:
16 %classificationRate : the number of correctly classified samples divided by
17 %all samples
18 % prec: precisions for each class
19 % recall: recall for each class
20 % f1s: f1 score for each class
21 
22 labels = labels(:);
23 groundTruth = groundTruth(:);
24 if nargin < 3
25  nbClasses = max(groundTruth);
26 end
27 prec = zeros(1, nbClasses);
28 recall = zeros(1, nbClasses);
29 for i = 1:nbClasses
30  TP = sum(labels==i & groundTruth==i);
31  FP = sum(labels==i & groundTruth~=i);
32  FN = sum(labels~=i & groundTruth==i);
33  prec(i) = TP/(TP+FP);
34  recall(i) = TP/(TP+FN);
35 end
36 
37 f1s = 2*prec.*recall./(prec+recall);
38 classificationRate = sum(labels==groundTruth)/length(labels);
39 f1s(isnan(f1s)) = 0;
classificationPrec
function classificationPrec(in labels, in groundTruth, in nbClasses)