SHOGUN  3.2.1
 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 
14 #include <shogun/lib/config.h>
15 
17 #include <shogun/labels/Labels.h>
19 #include <shogun/io/SGIO.h>
20 
21 namespace shogun
22 {
23 
24 class CLabels;
25 
28 {
29  ACCURACY = 0,
30  ERROR_RATE = 10,
31  BAL = 20,
32  WRACC = 30,
33  F1 = 40,
35  RECALL = 60,
36  PRECISION = 70,
38  CUSTOM = 999
39 };
40 
73 {
74 
75 public:
76 
80 
85  CBinaryClassEvaluation(), m_type(type), m_computed(false) {};
86 
89 
95  virtual float64_t evaluate(CLabels* predicted, CLabels* ground_truth);
96 
98 
100  virtual const char* get_name() const
101  {
102  return "ContingencyTableEvaluation";
103  }
104 
108  inline float64_t get_accuracy() const
109  {
110  if (!m_computed)
111  SG_ERROR("Uninitialized, please call evaluate first")
112 
113  return (m_TP+m_TN)/m_N;
114  };
115 
119  inline float64_t get_error_rate() const
120  {
121  if (!m_computed)
122  SG_ERROR("Uninitialized, please call evaluate first")
123 
124  return (m_FP + m_FN)/m_N;
125  };
126 
130  inline float64_t get_BAL() const
131  {
132  if (!m_computed)
133  SG_ERROR("Uninitialized, please call evaluate first")
134 
135  return 0.5*(m_FN/(m_FN + m_TP) + m_FP/(m_FP + m_TN));
136  };
137 
141  inline float64_t get_WRACC() const
142  {
143  if (!m_computed)
144  SG_ERROR("Uninitialized, please call evaluate first")
145 
146  return m_TP/(m_FN + m_TP) - m_FP/(m_FP + m_TN);
147  };
148 
152  inline float64_t get_F1() const
153  {
154  if (!m_computed)
155  SG_ERROR("Uninitialized, please call evaluate first")
156 
157  return (2*m_TP)/(2*m_TP + m_FP + m_FN);
158  };
159 
164  {
165  if (!m_computed)
166  SG_ERROR("Uninitialized, please call evaluate first")
167 
168  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));
169  };
170 
174  inline float64_t get_recall() const
175  {
176  if (!m_computed)
177  SG_ERROR("Uninitialized, please call evaluate first")
178 
179  return m_TP/(m_TP+m_FN);
180  };
181 
185  inline float64_t get_precision() const
186  {
187  if (!m_computed)
188  SG_ERROR("Uninitialized, please call evaluate first")
189 
190  return m_TP/(m_TP+m_FP);
191  };
192 
196  inline float64_t get_specificity() const
197  {
198  if (!m_computed)
199  SG_ERROR("Uninitialized, please call evaluate first")
200 
201  return m_TN/(m_TN+m_FP);
202  };
203 
208  {
209  return m_TP;
210  }
215  {
216  return m_FP;
217  }
222  {
223  return m_TN;
224  }
229  {
230  return m_FN;
231  }
232 
237  {
239  return 0.0;
240  }
241 
246  {
248  return ED_MAXIMIZE;
249  }
250 
251 protected:
252 
254  void compute_scores(CBinaryLabels* predicted, CBinaryLabels* ground_truth);
255 
258 
261 
263  int32_t m_N;
264 
267 
270 
273 
276 };
277 
288 {
289 public:
290  /* constructor */
292  /* virtual destructor */
293  virtual ~CAccuracyMeasure() {};
294  /* name */
295  virtual const char* get_name() const { return "AccuracyMeasure"; };
296 };
297 
308 {
309 public:
310  /* constructor */
312  /* virtual destructor */
313  virtual ~CErrorRateMeasure() {};
314  /* name */
315  virtual const char* get_name() const { return "ErrorRateMeasure"; };
316 };
317 
328 {
329 public:
330  /* constructor */
332  /* virtual destructor */
333  virtual ~CBALMeasure() {};
334  /* name */
335  virtual const char* get_name() const { return "BALMeasure"; };
336 };
337 
348 {
349 public:
350  /* constructor */
352  /* virtual destructor */
353  virtual ~CWRACCMeasure() {};
354  /* name */
355  virtual const char* get_name() const { return "WRACCMeasure"; };
356 };
357 
368 {
369 public:
370  /* constructor */
372  /* virtual destructor */
373  virtual ~CF1Measure() {};
374  /* name */
375  virtual const char* get_name() const { return "F1Measure"; };
376 };
377 
388 {
389 public:
390  /* constructor */
392  /* virtual destructor */
394  /* name */
395  virtual const char* get_name() const { return "CrossCorrelationMeasure"; };
396 };
397 
408 {
409 public:
410  /* constructor */
412  /* virtual destructor */
413  virtual ~CRecallMeasure() {};
414  /* name */
415  virtual const char* get_name() const { return "RecallMeasure"; };
416 };
417 
428 {
429 public:
430  /* constructor */
432  /* virtual destructor */
433  virtual ~CPrecisionMeasure() {};
434  /* name */
435  virtual const char* get_name() const { return "PrecisionMeasure"; };
436 };
437 
448 {
449 public:
450  /* constructor */
452  /* virtual destructor */
453  virtual ~CSpecificityMeasure() {};
454  /* name */
455  virtual const char* get_name() const { return "SpecificityMeasure"; };
456 };
457 }
458 #endif /* CONTINGENCYTABLEEVALUATION_H_ */

SHOGUN Machine Learning Toolbox - Documentation