Class EvaluationNDC


  • public class EvaluationNDC
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void createTestAndTrainSatasets​(int percent)  
      double discriminationInData​(Instances dataset)  
      void doEvaluate()  
      double[][] evaluate​(J48WithNDCs fairTree, J48WithNDCs normalTree, Instances dataset)  
      double[] getAccuracy()  
      double[][] getDiscrimination()
      public void ev(Instances instances) throws Exception { double[][] result = new double[2][2]; double nsiData = 0; // numSensitiveInstancesIn dataset double nfiData = 0; double nasiFairTree = 0; // numAcceptedSensitiveInstancesFairTree double nafiFairTree = 0; // numAcceptedFavorabelInstancesInFairTree double nasiNormalTree = 0; // numAcceptedSensitiveInstancesNormalTree double nafiNormalTree = 0; // numAcceptedFavorabelInstancesInNormalTree double numCorrectPredictionFairTree = 0; double numCorrectPredictionNormalTree = 0; double correctnessFairTree = 0; double correctnessNormalTree = 0; for (int i = 0; i < dataset.numInstances() ; i++) { Instance inst = dataset.instance(i); int resultFair = (int) Math.round(fairTree.classifyInstance(inst)); int resultNormal = (int) Math.round(normalTree.classifyInstance(inst)); if (dataset.instance(i).stringValue(sensitiveAttributeIndex).equals("protected_value")) { nsiData++; if (resultFair == 0 ) { nasiFairTree++; } if (resultNormal == 0 ) { nasiNormalTree++; } } else { nfiData++; if (resultFair == 0 ) { nafiFairTree++; } if (resultNormal == 0 ) { nafiNormalTree++; } } } // System.out.println("ev disc fair :"+ ((nafiFairTree/nfiData)-(nasiFairTree/nsiData))); // System.out.println("ev disc normal :"+ ((nafiNormalTree/nfiData)-(nasiNormalTree/nsiData))); }
      java.lang.String toStringAccuracy()  
      java.lang.String toStringDiscrimination()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EvaluationNDC

        public EvaluationNDC​(J48WithNDCs fairTree,
                             J48WithNDCs normalTree,
                             Instances dataset,
                             int sensitiveAttributeIndex)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • createTestAndTrainSatasets

        public void createTestAndTrainSatasets​(int percent)
      • doEvaluate

        public void doEvaluate()
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • discriminationInData

        public double discriminationInData​(Instances dataset)
      • evaluate

        public double[][] evaluate​(J48WithNDCs fairTree,
                                   J48WithNDCs normalTree,
                                   Instances dataset)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getDiscrimination

        public double[][] getDiscrimination()
        public void ev(Instances instances) throws Exception { double[][] result = new double[2][2]; double nsiData = 0; // numSensitiveInstancesIn dataset double nfiData = 0; double nasiFairTree = 0; // numAcceptedSensitiveInstancesFairTree double nafiFairTree = 0; // numAcceptedFavorabelInstancesInFairTree double nasiNormalTree = 0; // numAcceptedSensitiveInstancesNormalTree double nafiNormalTree = 0; // numAcceptedFavorabelInstancesInNormalTree double numCorrectPredictionFairTree = 0; double numCorrectPredictionNormalTree = 0; double correctnessFairTree = 0; double correctnessNormalTree = 0; for (int i = 0; i < dataset.numInstances() ; i++) { Instance inst = dataset.instance(i); int resultFair = (int) Math.round(fairTree.classifyInstance(inst)); int resultNormal = (int) Math.round(normalTree.classifyInstance(inst)); if (dataset.instance(i).stringValue(sensitiveAttributeIndex).equals("protected_value")) { nsiData++; if (resultFair == 0 ) { nasiFairTree++; } if (resultNormal == 0 ) { nasiNormalTree++; } } else { nfiData++; if (resultFair == 0 ) { nafiFairTree++; } if (resultNormal == 0 ) { nafiNormalTree++; } } } // System.out.println("ev disc fair :"+ ((nafiFairTree/nfiData)-(nasiFairTree/nsiData))); // System.out.println("ev disc normal :"+ ((nafiNormalTree/nfiData)-(nasiNormalTree/nsiData))); }
      • toStringDiscrimination

        public java.lang.String toStringDiscrimination()
      • getAccuracy

        public double[] getAccuracy()
      • toStringAccuracy

        public java.lang.String toStringAccuracy()