ContingencyTableEvaluation.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2011 Sergey Lisitsyn
00008  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00009  */
00010 
00011 #include <shogun/evaluation/ContingencyTableEvaluation.h>
00012 
00013 using namespace shogun;
00014 
00015 float64_t CContingencyTableEvaluation::evaluate(CLabels* predicted, CLabels* ground_truth)
00016 {
00017     compute_scores(predicted,ground_truth);
00018     switch (m_type)
00019     {
00020         case ACCURACY:
00021             return get_accuracy();
00022         case ERROR_RATE:
00023             return get_error_rate();
00024         case BAL:
00025             return get_BAL();
00026         case WRACC:
00027             return get_WRACC();
00028         case F1:
00029             return get_F1();
00030         case CROSS_CORRELATION:
00031             return get_cross_correlation();
00032         case RECALL:
00033             return get_recall();
00034         case PRECISION:
00035             return get_precision();
00036         case SPECIFICITY:
00037             return get_specificity();
00038     }
00039 
00040     SG_NOTIMPLEMENTED;
00041     return 42;
00042 }
00043 
00044 inline EEvaluationDirection CContingencyTableEvaluation::get_evaluation_direction()
00045 {
00046     switch (m_type)
00047     {
00048     case ACCURACY:
00049         return ED_MAXIMIZE;
00050     case ERROR_RATE:
00051         return ED_MINIMIZE;
00052     case BAL:
00053         return ED_MINIMIZE;
00054     case WRACC:
00055         return ED_MAXIMIZE;
00056     case F1:
00057         return ED_MAXIMIZE;
00058     case CROSS_CORRELATION:
00059         return ED_MAXIMIZE;
00060     case RECALL:
00061         return ED_MAXIMIZE;
00062     case PRECISION:
00063         return ED_MAXIMIZE;
00064     case SPECIFICITY:
00065         return ED_MAXIMIZE;
00066     default:
00067         SG_NOTIMPLEMENTED;
00068     }
00069 
00070     return ED_MINIMIZE;
00071 }
00072 
00073 void CContingencyTableEvaluation::compute_scores(CLabels* predicted, CLabels* ground_truth)
00074 {
00075     ASSERT(ground_truth->is_two_class_labeling());
00076     ASSERT(predicted->get_num_labels()==ground_truth->get_num_labels());
00077     m_TP = 0.0;
00078     m_FP = 0.0;
00079     m_TN = 0.0;
00080     m_FN = 0.0;
00081     m_N = predicted->get_num_labels();
00082 
00083     for (int i=0; i<predicted->get_num_labels(); i++)
00084     {
00085         if (ground_truth->get_label(i)==1)
00086         {
00087             if (CMath::sign(predicted->get_label(i))==1)
00088                 m_TP += 1.0;
00089             else
00090                 m_FN += 1.0;
00091         }
00092         else
00093         {
00094             if (CMath::sign(predicted->get_label(i))==1)
00095                 m_FP += 1.0;
00096             else
00097                 m_TN += 1.0;
00098         }
00099     }
00100     m_computed = true;
00101 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation