SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ContingencyTableEvaluation.h
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 #ifndef CONTINGENCYTABLEEVALUATION_H_
12 #define CONTINGENCYTABLEEVALUATION_H_
13 
15 #include <shogun/labels/Labels.h>
17 #include <shogun/io/SGIO.h>
18 
19 namespace shogun
20 {
21 
22 class CLabels;
23 
26 {
27  ACCURACY = 0,
28  ERROR_RATE = 10,
29  BAL = 20,
30  WRACC = 30,
31  F1 = 40,
33  RECALL = 60,
34  PRECISION = 70,
36 };
37 
70 {
71 
72 public:
73 
77 
82  CBinaryClassEvaluation(), m_type(type), m_computed(false) {};
83 
86 
92  virtual float64_t evaluate(CLabels* predicted, CLabels* ground_truth);
93 
95 
97  virtual inline const char* get_name() const
98  {
99  return "ContingencyTableEvaluation";
100  }
101 
105  inline float64_t get_accuracy() const
106  {
107  if (!m_computed)
108  SG_ERROR("Uninitialized, please call evaluate first");
109 
110  return (m_TP+m_TN)/m_N;
111  };
112 
116  inline float64_t get_error_rate() const
117  {
118  if (!m_computed)
119  SG_ERROR("Uninitialized, please call evaluate first");
120 
121  return (m_FP + m_FN)/m_N;
122  };
123 
127  inline float64_t get_BAL() const
128  {
129  if (!m_computed)
130  SG_ERROR("Uninitialized, please call evaluate first");
131 
132  return 0.5*(m_FN/(m_FN + m_TP) + m_FP/(m_FP + m_TN));
133  };
134 
138  inline float64_t get_WRACC() const
139  {
140  if (!m_computed)
141  SG_ERROR("Uninitialized, please call evaluate first");
142 
143  return m_TP/(m_FN + m_TP) - m_FP/(m_FP + m_TN);
144  };
145 
149  inline float64_t get_F1() const
150  {
151  if (!m_computed)
152  SG_ERROR("Uninitialized, please call evaluate first");
153 
154  return (2*m_TP)/(2*m_TP + m_FP + m_FN);
155  };
156 
161  {
162  if (!m_computed)
163  SG_ERROR("Uninitialized, please call evaluate first");
164 
165  return (m_TP*m_TN-m_FP*m_FN)/CMath::sqrt((m_TP+m_FP)*(m_TP+m_FN)*(m_TN+m_FP)*(m_TN+m_FN));
166  };
167 
171  inline float64_t get_recall() const
172  {
173  if (!m_computed)
174  SG_ERROR("Uninitialized, please call evaluate first");
175 
176  return m_TP/(m_TP+m_FN);
177  };
178 
182  inline float64_t get_precision() const
183  {
184  if (!m_computed)
185  SG_ERROR("Uninitialized, please call evaluate first");
186 
187  return m_TP/(m_TP+m_FP);
188  };
189 
193  inline float64_t get_specificity() const
194  {
195  if (!m_computed)
196  SG_ERROR("Uninitialized, please call evaluate first");
197 
198  return m_TN/(m_TN+m_FP);
199  };
200 
201 protected:
202 
204  void compute_scores(CBinaryLabels* predicted, CBinaryLabels* ground_truth);
205 
208 
211 
213  int32_t m_N;
214 
217 
220 
223 
226 };
227 
238 {
239 public:
240  /* constructor */
242  /* virtual destructor */
243  virtual ~CAccuracyMeasure() {};
244  /* name */
245  virtual inline const char* get_name() const { return "AccuracyMeasure"; };
246 };
247 
258 {
259 public:
260  /* constructor */
262  /* virtual destructor */
263  virtual ~CErrorRateMeasure() {};
264  /* name */
265  virtual inline const char* get_name() const { return "ErrorRateMeasure"; };
266 };
267 
278 {
279 public:
280  /* constructor */
282  /* virtual destructor */
283  virtual ~CBALMeasure() {};
284  /* name */
285  virtual inline const char* get_name() const { return "BALMeasure"; };
286 };
287 
298 {
299 public:
300  /* constructor */
302  /* virtual destructor */
303  virtual ~CWRACCMeasure() {};
304  /* name */
305  virtual inline const char* get_name() const { return "WRACCMeasure"; };
306 };
307 
318 {
319 public:
320  /* constructor */
322  /* virtual destructor */
323  virtual ~CF1Measure() {};
324  /* name */
325  virtual inline const char* get_name() const { return "F1Measure"; };
326 };
327 
338 {
339 public:
340  /* constructor */
342  /* virtual destructor */
344  /* name */
345  virtual inline const char* get_name() const { return "CrossCorrelationMeasure"; };
346 };
347 
358 {
359 public:
360  /* constructor */
362  /* virtual destructor */
363  virtual ~CRecallMeasure() {};
364  /* name */
365  virtual inline const char* get_name() const { return "RecallMeasure"; };
366 };
367 
378 {
379 public:
380  /* constructor */
382  /* virtual destructor */
383  virtual ~CPrecisionMeasure() {};
384  /* name */
385  virtual inline const char* get_name() const { return "PrecisionMeasure"; };
386 };
387 
398 {
399 public:
400  /* constructor */
402  /* virtual destructor */
403  virtual ~CSpecificityMeasure() {};
404  /* name */
405  virtual inline const char* get_name() const { return "SpecificityMeasure"; };
406 };
407 }
408 #endif /* CONTINGENCYTABLEEVALUATION_H_ */

SHOGUN Machine Learning Toolbox - Documentation