SHOGUN  v3.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  CUSTOM = 999
37 };
38 
71 {
72 
73 public:
74 
78 
83  CBinaryClassEvaluation(), m_type(type), m_computed(false) {};
84 
87 
93  virtual float64_t evaluate(CLabels* predicted, CLabels* ground_truth);
94 
96 
98  virtual const char* get_name() const
99  {
100  return "ContingencyTableEvaluation";
101  }
102 
106  inline float64_t get_accuracy() const
107  {
108  if (!m_computed)
109  SG_ERROR("Uninitialized, please call evaluate first")
110 
111  return (m_TP+m_TN)/m_N;
112  };
113 
117  inline float64_t get_error_rate() const
118  {
119  if (!m_computed)
120  SG_ERROR("Uninitialized, please call evaluate first")
121 
122  return (m_FP + m_FN)/m_N;
123  };
124 
128  inline float64_t get_BAL() const
129  {
130  if (!m_computed)
131  SG_ERROR("Uninitialized, please call evaluate first")
132 
133  return 0.5*(m_FN/(m_FN + m_TP) + m_FP/(m_FP + m_TN));
134  };
135 
139  inline float64_t get_WRACC() const
140  {
141  if (!m_computed)
142  SG_ERROR("Uninitialized, please call evaluate first")
143 
144  return m_TP/(m_FN + m_TP) - m_FP/(m_FP + m_TN);
145  };
146 
150  inline float64_t get_F1() const
151  {
152  if (!m_computed)
153  SG_ERROR("Uninitialized, please call evaluate first")
154 
155  return (2*m_TP)/(2*m_TP + m_FP + m_FN);
156  };
157 
162  {
163  if (!m_computed)
164  SG_ERROR("Uninitialized, please call evaluate first")
165 
166  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));
167  };
168 
172  inline float64_t get_recall() const
173  {
174  if (!m_computed)
175  SG_ERROR("Uninitialized, please call evaluate first")
176 
177  return m_TP/(m_TP+m_FN);
178  };
179 
183  inline float64_t get_precision() const
184  {
185  if (!m_computed)
186  SG_ERROR("Uninitialized, please call evaluate first")
187 
188  return m_TP/(m_TP+m_FP);
189  };
190 
194  inline float64_t get_specificity() const
195  {
196  if (!m_computed)
197  SG_ERROR("Uninitialized, please call evaluate first")
198 
199  return m_TN/(m_TN+m_FP);
200  };
201 
206  {
207  return m_TP;
208  }
213  {
214  return m_FP;
215  }
220  {
221  return m_TN;
222  }
227  {
228  return m_FN;
229  }
230 
235  {
237  return 0.0;
238  }
239 
244  {
246  return ED_MAXIMIZE;
247  }
248 
249 protected:
250 
252  void compute_scores(CBinaryLabels* predicted, CBinaryLabels* ground_truth);
253 
256 
259 
261  int32_t m_N;
262 
265 
268 
271 
274 };
275 
286 {
287 public:
288  /* constructor */
290  /* virtual destructor */
291  virtual ~CAccuracyMeasure() {};
292  /* name */
293  virtual const char* get_name() const { return "AccuracyMeasure"; };
294 };
295 
306 {
307 public:
308  /* constructor */
310  /* virtual destructor */
311  virtual ~CErrorRateMeasure() {};
312  /* name */
313  virtual const char* get_name() const { return "ErrorRateMeasure"; };
314 };
315 
326 {
327 public:
328  /* constructor */
330  /* virtual destructor */
331  virtual ~CBALMeasure() {};
332  /* name */
333  virtual const char* get_name() const { return "BALMeasure"; };
334 };
335 
346 {
347 public:
348  /* constructor */
350  /* virtual destructor */
351  virtual ~CWRACCMeasure() {};
352  /* name */
353  virtual const char* get_name() const { return "WRACCMeasure"; };
354 };
355 
366 {
367 public:
368  /* constructor */
370  /* virtual destructor */
371  virtual ~CF1Measure() {};
372  /* name */
373  virtual const char* get_name() const { return "F1Measure"; };
374 };
375 
386 {
387 public:
388  /* constructor */
390  /* virtual destructor */
392  /* name */
393  virtual const char* get_name() const { return "CrossCorrelationMeasure"; };
394 };
395 
406 {
407 public:
408  /* constructor */
410  /* virtual destructor */
411  virtual ~CRecallMeasure() {};
412  /* name */
413  virtual const char* get_name() const { return "RecallMeasure"; };
414 };
415 
426 {
427 public:
428  /* constructor */
430  /* virtual destructor */
431  virtual ~CPrecisionMeasure() {};
432  /* name */
433  virtual const char* get_name() const { return "PrecisionMeasure"; };
434 };
435 
446 {
447 public:
448  /* constructor */
450  /* virtual destructor */
451  virtual ~CSpecificityMeasure() {};
452  /* name */
453  virtual const char* get_name() const { return "SpecificityMeasure"; };
454 };
455 }
456 #endif /* CONTINGENCYTABLEEVALUATION_H_ */

SHOGUN Machine Learning Toolbox - Documentation