def testGermanCreditDataCreation(self):
     protected, nonProtected = germanCreditData.create(
         "test_dataset_creator/GermanCredit_sex.csv",
         "DurationMonth",
         "CreditAmount",
         "score",
         "sex",
         protectedAttribute=["female"])
     self.assertEqual(310, len(nonProtected), "should have 310 males")
     self.assertEqual(
         0, countProtected(nonProtected),
         "the nonProtected array should not contain protected candidates")
     self.assertAlmostEqual(
         0.744449197,
         nonProtected[0].originalQualification,
         places=9,
         msg="best non-protected candidate has wrong score")
     self.assertEqual(690, len(protected), "should have 690 females")
     self.assertEqual(
         690, countProtected(protected),
         "the protected ranking should contain only protected candidates")
     self.assertAlmostEqual(0.790280217,
                            protected[0].originalQualification,
                            places=9,
                            msg="best protected candidate has wrong score")
Beispiel #2
0
 def testDatasetCreationGender(self):
     # the csv file contains 310 male persons and 690 female
     protected, nonProtected = compasData.createGender("ProPublica_sex.csv", "sex", "Violence_rawscore", "Recidivism_rawscore",
    "priors_count")
     self.assertEqual(1328, len(nonProtected), "should have 1328 females")
     self.assertEqual(0, countProtected(nonProtected), "the nonProtected array should not contain protected candidates")
     # for COMPAS we take the negativ recidivism score
     self.assertEqual(1 - 0.038379531, nonProtected[0].originalQualification, "best non-protected candidate has wrong score")
     self.assertEqual(5561, len(protected), "should have 5561 males")
     self.assertEqual(5561, countProtected(protected), "the protected ranking should contain only protected candidates")
     # for COMPAS we take the negativ recidivism score
     self.assertEqual(1 - 0, protected[0].originalQualification, "best protected candidate has wrong score")
Beispiel #3
0
 def testDatasetCreationRace(self):
     # the csv file contains 310 male persons and 690 female
     protected, nonProtected = compasData.createRace("ProPublica_race.csv", "race", "Violence_rawscore", "Recidivism_rawscore",
    "priors_count")
     self.assertEqual(3361, len(nonProtected), "should have 3361 non-blacks")
     self.assertEqual(0, countProtected(nonProtected), "the nonProtected array should not contain protected candidates")
     # for COMPAS we take the negativ recidivism score
     self.assertEqual(1 - 0, nonProtected[0].originalQualification, "best non-protected candidate has wrong score")
     self.assertEqual(3528, len(protected), "should have 3528 blacks")
     self.assertEqual(3528, countProtected(protected), "the protected ranking should contain only protected candidates")
     # for COMPAS we take the negativ recidivism score
     self.assertEqual(1 - 0.012793177, protected[0].originalQualification, "best protected candidate has wrong score")
Beispiel #4
0
    def fair_representation_condition(self, ranking):
        """
        checks if a given ranking with tau_p protected candidates fairly represents the protected group. A
        minimal proportion of protected candidates is defined in advance.

        Parameters:
        ----------
        ranking : [Candidate]
        the set to be checked for fair representation

        Return:
        ------
        True if the ranking fairly represents the protected group, False otherwise
        """

        t = len(ranking)
        numberProtected = countProtected(ranking)

        if self.__candidatesNeeded[t - 1] > numberProtected:
            # not enough protected candidates in my ranking
            return False
        else:
            return True
Beispiel #5
0
def percentageOfProtected(ranking):
    return countProtected(ranking) / len(ranking)