-
Notifications
You must be signed in to change notification settings - Fork 14
/
computeAccuracy.m
57 lines (53 loc) · 1.81 KB
/
computeAccuracy.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
48
49
50
51
52
53
54
55
56
57
function accuracy = computeAccuracy(Y,Yhat)
% Computes the accuracy of ELM predictions
%
%
%
% Copyright 2015 Riccardo Taormina ([email protected]),
% Gulsah Karakaya ([email protected];),
% Stefano Galelli ([email protected]),
% and Selin Damla Ahipasaoglu ([email protected];.
%
% Please refer to README.txt for further information.
%
%
% This file is part of Matlab-Multi-objective-Feature-Selection.
%
% Matlab-Multi-objective-Feature-Selection is free software: you can redistribute
% it and/or modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with MATLAB_IterativeInputSelection.
% If not, see <http://www.gnu.org/licenses/>.
classes = unique(Y);
nClasses = numel(unique(Y));
if nClasses == 2
nClasses = 1; % handle binary classification
end
Acc = zeros(1,nClasses);
for j = 1 : nClasses
if nClasses == 1
thisClass = 2; % the H1
else
thisClass = classes(j);
end
% ixes
ixes1 = (Y == thisClass);
ixes2 = (Yhat == thisClass);
% compute confusion matrix
tp = sum((ixes1==ixes2)&(ixes1==1));
tn = sum((ixes1==ixes2)&(ixes1==0));
fn = sum((ixes1-ixes2)==1);
fp = sum((ixes1-ixes2)==-1);
% compute accuracy
Acc(j) = (tp+tn)/(tp+fn+fp+tn);
end
% get average accuracy
accuracy = mean(Acc);