Browse Source

more classification statistics

Sven Sickert 9 years ago
parent
commit
f234544b6c
1 changed files with 24 additions and 14 deletions
  1. 24 14
      semseg/SemSegTools.cpp

+ 24 - 14
semseg/SemSegTools.cpp

@@ -109,22 +109,28 @@ void SemSegTools::computeClassificationStatistics(
 
     overallTrue /= sumAll;
 
-    double truePos = (double)confMat(1,1);
-    //double trueNeg = (double)confMat(0,0);
-    double falsePos = (double)confMat(0,1);
-    double falseNeg = (double)confMat(1,0);
+    double precision = 0.0, recall = 0.0, f1score = 0.0, iuScore = 0.0;
 
-    // binary classification metrics
-    if ( classMappingInv.size() == 2 )
+    // binary classification
+    for ( int c = 0; c < classMappingInv.size(); c++ )
     {
-        double precision = truePos / (truePos+falsePos);
-        double recall = truePos / (truePos+falseNeg);
-        double f1score = 2.0*(precision*recall)/(precision+recall);
-        std::cout << "Precision: " << precision;
-        std::cout << "\nRecall: " << recall;
-        std::cout << "\nF1Score: " << f1score << "\n\n";
+        double precBase = 0.0, recBase = 0.0;
+        for ( int r = 0; r < classMappingInv.size(); r++ )
+            precBase += confMat(r,c);
+
+        for ( int cc = 0; cc < classMappingInv.size(); cc++ )
+            recBase += confMat(c,cc);
+
+        precision += confMat(c,c) / precBase;
+        recall += confMat(c,c) / recBase;
+        iuScore += confMat(c,c) / (precBase+recBase-confMat(c,c));
     }
 
+    precision /= classMappingInv.size();
+    recall /= classMappingInv.size();
+    iuScore /= classMappingInv.size();
+    f1score = 2.0*(precision*recall)/(precision+recall);
+
     // normalizing confMat using rows
     for ( int r = 0 ; r < (int) confMat.rows() ; r++ )
     {
@@ -170,8 +176,12 @@ void SemSegTools::computeClassificationStatistics(
     }
 
     // print classification statistics
-    std::cout << "\nOverall Recognition Rate: " << overallTrue;
-    std::cout << "\nAverage Recognition Rate: " << confMat.trace() / (double)classMappingInv.size();
+    std::cout << "\nAccuracy: " << overallTrue;
+    std::cout << "\nPrecision: " << precision;
+    std::cout << "\nRecall: " << recall;
+    std::cout << "\nF1Score: " << f1score;
+    std::cout << "\nIU: " << iuScore;
+    std::cout << "\n\nAverage Recognition Rate: " << confMat.trace() / (double)classMappingInv.size();
     std::cout << "\nLower Bound: " << 1.0 /(double)classMappingInv.size();
     std::cout << std::endl;
 }