SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
evaluation
ContingencyTableEvaluation.cpp
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 2011 Sergey Lisitsyn
8
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9
*/
10
11
#include <
shogun/evaluation/ContingencyTableEvaluation.h
>
12
13
using namespace
shogun;
14
15
float64_t
CContingencyTableEvaluation::evaluate
(
CLabels
* predicted,
CLabels
* ground_truth)
16
{
17
compute_scores
(predicted,ground_truth);
18
switch
(
m_type
)
19
{
20
case
ACCURACY
:
21
return
get_accuracy
();
22
case
ERROR_RATE
:
23
return
get_error_rate
();
24
case
BAL
:
25
return
get_BAL
();
26
case
WRACC
:
27
return
get_WRACC
();
28
case
F1
:
29
return
get_F1
();
30
case
CROSS_CORRELATION
:
31
return
get_cross_correlation
();
32
case
RECALL
:
33
return
get_recall
();
34
case
PRECISION
:
35
return
get_precision
();
36
case
SPECIFICITY
:
37
return
get_specificity
();
38
}
39
40
SG_NOTIMPLEMENTED
;
41
return
42;
42
}
43
44
inline
EEvaluationDirection
CContingencyTableEvaluation::get_evaluation_direction
()
45
{
46
switch
(
m_type
)
47
{
48
case
ACCURACY
:
49
return
ED_MAXIMIZE
;
50
case
ERROR_RATE
:
51
return
ED_MINIMIZE
;
52
case
BAL
:
53
return
ED_MINIMIZE
;
54
case
WRACC
:
55
return
ED_MAXIMIZE
;
56
case
F1
:
57
return
ED_MAXIMIZE
;
58
case
CROSS_CORRELATION
:
59
return
ED_MAXIMIZE
;
60
case
RECALL
:
61
return
ED_MAXIMIZE
;
62
case
PRECISION
:
63
return
ED_MAXIMIZE
;
64
case
SPECIFICITY
:
65
return
ED_MAXIMIZE
;
66
default
:
67
SG_NOTIMPLEMENTED
;
68
}
69
70
return
ED_MINIMIZE
;
71
}
72
73
void
CContingencyTableEvaluation::compute_scores
(
CLabels
* predicted,
CLabels
* ground_truth)
74
{
75
ASSERT
(ground_truth->
is_two_class_labeling
());
76
ASSERT
(predicted->
get_num_labels
()==ground_truth->
get_num_labels
());
77
m_TP
= 0.0;
78
m_FP
= 0.0;
79
m_TN
= 0.0;
80
m_FN
= 0.0;
81
m_N
= predicted->
get_num_labels
();
82
83
for
(
int
i=0; i<predicted->
get_num_labels
(); i++)
84
{
85
if
(ground_truth->
get_label
(i)==1)
86
{
87
if
(
CMath::sign
(predicted->
get_label
(i))==1)
88
m_TP += 1.0;
89
else
90
m_FN
+= 1.0;
91
}
92
else
93
{
94
if
(
CMath::sign
(predicted->
get_label
(i))==1)
95
m_FP
+= 1.0;
96
else
97
m_TN
+= 1.0;
98
}
99
}
100
m_computed
=
true
;
101
}
SHOGUN
Machine Learning Toolbox - Documentation