-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiasTest.java
132 lines (109 loc) · 4.83 KB
/
BiasTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package recommender.sol;
import tester.Tester;
import java.util.LinkedList;
/*
* Test to show the bias of the datasets
*/
public class BiasTest {
BiasTest() {
}
/**
* NOTE: Do not modify anything in the files except TODO:
*/
// the list of candidate objects to generate the tree on
static Dataset<Candidate> candidates;
/**
* A method to set up candidate attributes and training data
*/
public static void setupCandidates() {
LinkedList<String> canAttr = new LinkedList<String>();
// different attributes to consider similar to the Candidate class
canAttr.add("gender");
canAttr.add("leadershipExperience");
canAttr.add("lastPositionDuration");
canAttr.add("numWorkExperiences");
canAttr.add("programmingLanguages");
canAttr.add("gpa");
canAttr.add("location");
canAttr.add("hired");
/**
* TODO: change this filepath
*/
String filepath = "train_candidates_unequal.csv";
RecommenderCSVParser<Candidate> parser = new RecommenderCSVParser<Candidate>();
LinkedList<Candidate> allCandidates = new LinkedList<>();
// parsing the dataset in the form of a CSV file, CommaSeparatedValues.
allCandidates = (LinkedList<Candidate>) parser.parse(Candidate.class, filepath, ',', true);
// if the filename is the correlated variable, we're not looking at the gender
// variable at all while looking
// at different Candidate objects while building the tree.
if (filepath.equals("train_candidates_correlated.csv")) {
canAttr.remove("gender");
}
BiasTest.candidates = new Dataset<Candidate>(canAttr, allCandidates);
}
/**
* Main method for BiasTest
*
* @param args - the arguments to the program
*/
public static void main(String[] args) {
// set up the candidates from the CSV file
BiasTest.setupCandidates();
Tester.run(new BiasTest());
double male_ratio = 0.0;
double female_ratio = 0.0;
double distance = -Double.MIN_VALUE;
LinkedList<Candidate> newCandMale = new LinkedList<>();
LinkedList<Candidate> newCandFemale = new LinkedList<>();
RecommenderCSVParser<Candidate> parser = new RecommenderCSVParser<Candidate>();
/**
* TODO: While testing correlated variables, change filepath from
* "testing_cis_male.csv" to "testing_cis_male_correlated.csv"
*/
// parse the male testing dataset
newCandMale = (LinkedList<Candidate>) parser.parse(Candidate.class, "testing_cis_male.csv", ',', true);
// parse the female testing dataset
/**
* TODO: While testing correlated variables, change filepath from
* "testing_cis_female.csv" to "testing_cis_female_correlated.csv"
*/
newCandFemale = (LinkedList<Candidate>) parser.parse(Candidate.class, "testing_cis_female.csv", ',', true);
// loop to test female and male hiring ratios with the same test files but large
// number of times
// to determine a better ratio by volume
for (int j = 0; j < 10; j++) {
// build the tree
TreeGenerator<Candidate> builder = new TreeGenerator<Candidate>(BiasTest.candidates);
builder.buildClassifier("hired");
//TODO: remove
//builder.classifier.printNode("");
// loop to find out the number of males hired
double hiredYes = 0;
for (int i = 0; i < newCandMale.size(); i++) {
if (builder.lookupRecommendation(newCandMale.get(i)).equals(Boolean.TRUE)) {
hiredYes++;
}
}
// loop to find out number of females hired
double hiredYes1 = 0;
for (int i = 0; i < newCandFemale.size(); i++) {
if (builder.lookupRecommendation(newCandFemale.get(i)).equals(Boolean.TRUE)) {
hiredYes1++;
}
}
// update the highest distances between male and female hired ratios and male
// and female ratios respectively
if (distance < (hiredYes / newCandMale.size() - hiredYes1 / newCandFemale.size())) {
distance = hiredYes / newCandMale.size() - hiredYes1 / newCandFemale.size();
male_ratio = hiredYes / newCandMale.size();
female_ratio = hiredYes1 / newCandFemale.size();
}
}
/**
* NOTE: run the file again if you get ratios as zero.
*/
System.out.println("Cis Female ratio hired " + female_ratio);
System.out.println("Cis Male ratio hired " + male_ratio);
}
}