{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fair classifiers with adversarial networks\n", "\n", "Gilles Louppe, 2017." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We illustrate how one can use adversarial networks for building a classifier whose output is forced to be independent of some chosen attribute. We follow the adversarial networks setup described in \"Learning to Pivot with Adversarial Networks\" (Louppe, Kagan and Cranmer, 2016, [arXiv:1611.01046](https://arxiv.org/abs/1611.01046)).\n", "\n", "In this notebook, we will show more specifically how one can build a fair classifier whose decision is made independent of gender." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "@article{louppe2016pivot,\n", " author = {{Louppe}, G. and {Kagan}, M. and {Cranmer}, K.},\n", " title = \"{Learning to Pivot with Adversarial Networks}\",\n", " journal = {ArXiv e-prints},\n", " archivePrefix = \"arXiv\",\n", " eprint = {1611.01046},\n", " primaryClass = \"stat.ML\",\n", " year = 2016,\n", " month = nov,\n", "}\n", "```" ] }, { "cell_type": "code", "execution_count": 64, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from IPython import display\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Prepare data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are using the [adult](https://archive.ics.uci.edu/ml/datasets/Adult) UCI dataset, where the prediction task is to predict whether someone makes over 50,000$ a year." ] }, { "cell_type": "code", "execution_count": 65, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | Age | \n", "Workclass | \n", "fnlwgt | \n", "Education | \n", "Education-Num | \n", "Martial Status | \n", "Occupation | \n", "Relationship | \n", "Race | \n", "Sex | \n", "Capital Gain | \n", "Capital Loss | \n", "Hours per week | \n", "Country | \n", "Target | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "39 | \n", "State-gov | \n", "77516 | \n", "Bachelors | \n", "13 | \n", "Never-married | \n", "Adm-clerical | \n", "Not-in-family | \n", "White | \n", "Male | \n", "2174 | \n", "0 | \n", "40 | \n", "United-States | \n", "<=50K | \n", "
1 | \n", "50 | \n", "Self-emp-not-inc | \n", "83311 | \n", "Bachelors | \n", "13 | \n", "Married-civ-spouse | \n", "Exec-managerial | \n", "Husband | \n", "White | \n", "Male | \n", "0 | \n", "0 | \n", "13 | \n", "United-States | \n", "<=50K | \n", "
2 | \n", "38 | \n", "Private | \n", "215646 | \n", "HS-grad | \n", "9 | \n", "Divorced | \n", "Handlers-cleaners | \n", "Not-in-family | \n", "White | \n", "Male | \n", "0 | \n", "0 | \n", "40 | \n", "United-States | \n", "<=50K | \n", "
3 | \n", "53 | \n", "Private | \n", "234721 | \n", "11th | \n", "7 | \n", "Married-civ-spouse | \n", "Handlers-cleaners | \n", "Husband | \n", "Black | \n", "Male | \n", "0 | \n", "0 | \n", "40 | \n", "United-States | \n", "<=50K | \n", "
4 | \n", "28 | \n", "Private | \n", "338409 | \n", "Bachelors | \n", "13 | \n", "Married-civ-spouse | \n", "Prof-specialty | \n", "Wife | \n", "Black | \n", "Female | \n", "0 | \n", "0 | \n", "40 | \n", "Cuba | \n", "<=50K | \n", "