package performance;

import data.DataSet;
import data.core.Label;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.IntStream;

/**
 * Created by hanxuan on 9/20/15 for machine_learning.
 */
public class ClassificationEvaluator extends Evaluator{

    public ClassificationEvaluator() {}

    public double evaluate() {

        Label trueLabel = testSet.getLabels();
        int correct = 0;
        int instanceLength = testSet.getInstanceLength();
        for (int i = 0; i < instanceLength; i++) {
            if (trueLabel.getRow(i) == predictLabel.getRow(i)) ++ correct;
        }

        return correct * 1.0 / instanceLength;
    }
}

@@ -301,16 +301,262 @@
 uator%7B%0A%0A
+    private static final Logger log = LogManager.getLogger(ClassificationEvaluator.class);%0A%0A    private int truePos = 0;%0A%0A    private int falsePos = 0;%0A%0A    private int trueNeg = 0;%0A%0A    private int falseNeg = 0;%0A%0A//    private int correct = 0;%0A%0A
     publ
@@ -620,16 +620,70 @@
 te() %7B%0A%0A
+        truePos = trueNeg = falsePos = falseNeg = 0;%0A%0A
         
@@ -725,32 +725,8 @@
 ();%0A
-        int correct = 0;
 %0A   
@@ -847,127 +847,1054 @@
     
-if (trueLabel.getRow(i) == predictLabel.getRow(i)) ++ correct;%0A        %7D%0A%0A        return correct * 1.0 / instanceLength
+double trueValue = trueLabel.getRow(i);%0A            double predictValue = predictLabel.getRow(i);%0A            if (trueValue == 1 && predictValue == 1) ++ truePos;%0A            if (trueValue == 0 && predictValue == 1) ++ falsePos;%0A            if (trueValue == 1 && predictValue == 0) ++ falseNeg;%0A            if (trueValue == 0 && predictValue == 0) ++ trueNeg;%0A        %7D%0A%0A        printConfusionMatrix();%0A%0A        return (truePos + trueNeg) / (double) instanceLength;%0A    %7D%0A%0A    public void printConfusionMatrix() %7B%0A        log.info(%22================= confusion matrix =================%22);%0A%0A        log.info(%22TruePos: %7B%7D   FalsePos: %7B%7D%22, truePos, falsePos);%0A        log.info(%22FalseNeg: %7B%7D  TrueNeg: %7B%7D%22, falseNeg, trueNeg);%0A        log.info(%22precision: %7B%7D recall: %7B%7D%22, truePos / (double) (truePos + falsePos),%0A                truePos / (double) (truePos + falseNeg));%0A        log.info(%22accuracy: %7B%7D%22, (truePos + trueNeg) / (double) (truePos + trueNeg + falsePos + falseNeg));%0A        log.info(%22================= ================ =================%22)
 ;%0A  

add confusion matrix