Using machine learning to understand and reverse the gender pay gap
Whilst the gender pay gap is more complex than just comparing like for like salaries - including the types of roles in an organisation, how those roles and working conditions interact with family and other outside responsibilities, and the gender mix by role and across the organisation - assessing what an individual might earn if they were a different gender is one piece of the picture.
In the case of a recruitment looking to model target salary for candidates, evidencing that a salary expectation may be artificially deflated due to gender could increase the salary achievable for that individual and therefore the commission for the recruitment agency. Thinking of the many stories of biased training data propagating discrimination, I wanted to use this learned bias in a positive way (promoting fairness) by making it visible (providing interpretability). This article describes some of the techniques I used.
This graph below is an output of Python libraries called partial dependency which analyse the influence that each input variable has on a model's predictions.
This tells us how the model will behave in different scenarios. As well as displaying the impact that gender has on predictions, we can see the way that other variables interact with gender:
The great thing about this is we can apply it to algorithms which are themselves hard to interpret, which is true of the more powerful algorithms, such as the gradient boosting regressor I'm using here.
We can see that the model has learnt an increasing divergence between male and female as age increases, a slight decrease over time/year (inflation-adjusted) and a broadly consistent gap as years of education ("educ") increases.
Exploratory analysis of the actual source data such as the plot below shows that the model has learnt fairly accurately:
The variables shown above are four (including gender) of 10 socio economic factors the programme as input to predict earnings as the output. Rather than building one model I built three - one trained on both male and female samples, one trained on female only and one trained on male only.
We can then take a new female or male sample and compare the prediction made by each model, to see predict the gender gap for the particular mix of variables of the current sample. So where the partial dependency plots give us an overview of trends, running a single sample like this lets us isolate specific values. Here we take a female sample:
We can see that both the model trained on female-only data and the model trained on both sexes (with this record identified as female) predict fairly close to the actual value. The two alternatives show the prediction If everything else about the sample was the same except the sex - the model trained purely on male data and the joint model with this record identified as male.
Of course gender does not act alone in the model - it is becomes more or less pronounced due to combining with other variables as we saw in the partial dependency plots.
This may prompt us to want to know the impact that changing other variables could have. This is known as counter-factual explanation and useful in many situations when we want know the smallest possible change to achieve a desired result - not necessarily gender-related - for situations as varied as being granted a load, or to increasing life expectancy by say five years.
There are machine learning libraries available which will run your model for every / many permutations of input values to find the smallest change required to achieve the outcome. To demonstrate more explicitly, this programme allows you to change any value manually to see the result. First it displays the actual values for the record:
I can see from the partial dependency plot above that the combination gender = female and educ = 14 has an influence of roughly -$4,000 on the output. Increased education has a positive influence (or minimises the negative influence), with a step change at 16 years. I can test this scenario:
We can see that a further two years of education has a substantial impact on the prediction, with an increase of over $7,000 from the original $22,507. Whilst the partial dependency plot showed the interaction of education and gender, in the model education interacts with all other variables hence the difference from the increase predicted by the education-gender graph.
We could go on to test any combination of variables, enabling us to model many different scenarios for this specific record, which is of course not just an abstract piece of data, but a representation of an actual person to whom the outcomes are real and meaningful.
This hopefully demonstrates a way of analysing and explicitly using the bias inherent in training data to promote fairer outcomes in a way which can be beneficial not just to the data subject but also to the organisation performing the modelling - in this case a recruitment agency whose commission is determined by the individual's salary.