-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMultiLabelEvaluation.m
48 lines (39 loc) · 1.18 KB
/
MultiLabelEvaluation.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
45
46
47
function [ Scores ] = MultiLabelEvaluation( yyGroundTruth,yyPredicted )
% Evaluation Multilabel Classification
% input ===================================================================
% yyGroundTruth: true label of data [NTrain x CC]
% yyPredicted: label of predicted values [NTrain x CC]
% =========================================================================
% output ==================================================================
% Scores.F1 = F1 score
% Scores.ExactMatch = Exact Match score
% contact: anonymous
NN=size(yyGroundTruth,1);
NL=size(yyGroundTruth,2);
% F1
% Micro %Across Datapoints
Precision=zeros(1,NN);
Recall=zeros(1,NN);
F1_NN=zeros(1,NN);
TP=0;
TN=0;
FP=0;
FN=0;
idxPos=find(yyGroundTruth==1);
idxNeg=find(yyGroundTruth==0);
Pos=length(idxPos);
Neg=NN*NL-Pos;
TP=sum(yyGroundTruth(idxPos)==yyPredicted(idxPos));
TN=sum(yyGroundTruth(idxNeg)==yyPredicted(idxNeg));
FP=Neg-TN;
FN=Pos-TP;
Precision=TP/(TP+FP);
Recall=TP/(Pos);
F1=2*Precision*Recall/(Precision+Recall);
% exact match
temp_minus=abs(yyPredicted-yyGroundTruth);
temp_sum=sum(temp_minus,2);
ExactMatchScore=length(find(temp_sum==0))/NN;
Scores.F1=F1;
Scores.ExactMatch=ExactMatchScore;
end