Fairness and transparency in
machine learning
Tools and techniques
PyData Berlin – 2017
Andreas Dewes (@japh44)
Introduction:Why think about this?
Fairness in Machine Learning
• Fairness is not a technological problem, but unfair behavior
can be replicated / automated using technology.
• Machine learning systems are not per se fair or unfair, but
have the potential to be either depending on how we use them.
• We have a chance to eliminate unfairness by using machine
learning and data analysis to make personal biases explicit
and design systems that eliminate it!
Discrimination
Discrimination is treatment or consideration of, or making a
distinction in favor of or against, a person or thing based on the
group, class, or category to which that person or thing is
perceived to belong to rather than on individual merit.
Protected attributes (examples):
Ethnicity, Gender, Sexual Orientation, ...
When is a process discriminating?
Disparate Impact: Adverse impact of a process C on a given
group X
𝑃 𝐶 = 𝑌𝐸𝑆 𝑋 = 0
𝑃 𝐶 = 𝑌𝐸𝑆 𝑋 = 1
< τ
see e.g. "Certifying and Removing Disparate Impact" M. Feldman et. al.
Estimating  with real-world data
τ =
𝑐/ 𝑎 + 𝑐
𝑑/ 𝑏 + 𝑑
c
a
d
b
Alternative Approaches: Individual-Based
Fairness
𝑓 𝑥1 − 𝑓 𝑥2 ≤ 𝐿 𝑥1 − 𝑥2
similar individual => similar treatment!
Let‘s try to
design
a fair &
transparent
algorithm
NYC Stop &
Frisk Dataset
https://gist.github.com/dannguyen/67ece10c6132282b1da2
• Design a stop &
frisk algorithm
that is as fair as
possible
• Ensure it fulfills
the other goals
that we have for
it
InputVariables
appearance-related behavior-related
Attribute
Name
Description
Age SUSPECT'S AGE
Weight SUSPECT'S WEIGHT
Ht_feet SUSPECT'S HEIGHT (FEET)
Eyecolor SUSPECT'S EYE COLOR
Haircolor SUSPECT'S HAIRCOLOR
Race SUSPECT'S RACE
Sex SUSPECT'S SEX
Build SUSPECT'S BUILD
CS_Cloth WEARING CLOTHES COMMONLY USED IN A
CRIME
CS_Objcs CARRYING SUSPICIOUS OBJECT
CS_Bulge SUSPICIOUS BULGE
CS_Descr FITS A RELEVANT DESCRIPTION
RF_Attir INAPPROPRIATE ATTIRE FOR SEASON
Attribute
Name
Description
ac_evasv EVASIVE RESPONSE TO QUESTIONING
ac_assoc ASSOCIATING WITH KNOWN CRIMINALS
cs_lkout SUSPECT ACTING AS A LOOKOUT
cs_drgtr ACTIONS INDICATIVE OF A DRUG
TRANSACTION
cs_casng CASING A VICTIM OR LOCATION
cs_vcrim VIOLENT CRIME SUSPECTED
ac_cgdir CHANGE DIRECTION AT SIGHT OF OFFICER
cs_furtv FURTIVE MOVEMENTS
ac_stsnd SIGHTS OR SOUNDS OF CRIMINAL ACTIVITY
rf_othsw OTHER SUSPICION OF WEAPONS
rf_knowl KNOWLEDGE OF SUSPECTS PRIOR CRIMINAL
BEHAVIOR
rf_vcact ACTIONS OF ENGAGING IN A VIOLENT
CRIME
rf_verbl VERBAL THREATS BY SUSPECT
Attribute
Name
Description
inout WAS STOP INSIDE OR OUTSIDE?
trhsloc WAS LOCATION HOUSING OR
TRANSIT AUTHORITY?
timestop TIME OF STOP (HH:MM)
pct PRECINCT OF STOP (FROM 1 TO
123)
ac_prox
m
PROXIMITY TO SCENE OF OFFENSE
cs_other OTHER
ac_rept REPORT BY VICTIM / WITNESS /
OFFICER
ac_inves ONGOING INVESTIGATION
ac_incid AREA HAS HIGH CRIME INCIDENCE
ac_time TIME OF DAY FITS CRIME
INCIDENCE
circumstance-related
?
Process Model
Possible goals:
Build a system that decides
whether to frisk someone or
Try to maximize discovery of
criminals while not bothering
law-abiding citizens.
Do not discriminate against
individual groups of people.
Choosing A Loss Function
Give a reward α if our
algorithm correctly
identifies a person to frisk
Give a penalty -1 if our
algorithm wrongly
identifies a person to frisk
α (weight parameter)
„It‘s okay to frisk α +1 people to find one criminal“.
Measuring Fairness via DisparateTreatment
Building a First Model Clean input data
Select attributes
Convert to binary values
using „one hot“ method
Train a classifier on the
target value
Measure the score and
discrimination metrics
Load CSV data into dataframe,
discretize all attributes, clean
input data.
Use a logistic regression
classifier to predict the target
attribute.
Split the data in training/test
sets using a 70/30 split.
Generate models for a range of
α values and compare
performance.
First Attempt:To Frisk Or NotTo Frisk…
Input attributes was this person frisked?
HowTo JudgeThe Success Rate ofThe
Algorithm Our algorithm should at
least be as good as a
random algorithm at
picking people to frisk.
It can „buy“ true positives
by accepting false
positives. The higher α is,
the more profitable this
trade becomes.
Eventually we will have
frisked all people, which is
a solution to the problem
(but not a good one…)
Example: Predicting OnlyWith Noise (No
Information)
We give no useful
information to the
algorithm at all.
It will therefore pick
the action (frisk / not
frisk) that will globally
maximize the score
when chosen for all
people.
Predicting „frisk“ with all available input
attributes
Now we give it all
the input attributes
that we got.
It will make a
prediction that is
much better than
randomly choosing
a person to frisk.
What does it mean for individual groups?
There is strong
mistreatment of
individual groups.
The algorithm
learned to be just as
biased as the
training data.
Where does the bias come from?
Let‘s see!
Predict „black“
from available
attributes.
The algorithm can easily
differentiate between
„white“ and „black“
EliminatingThe Bias: Different Approaches
Remove /Modify
Data Points
…
1
2
3
Constrain the
Algorithm
forbidden
solutions
allowed
solutions
…or change the target attribute!
…
1
2
3
Remove Attributes
Trying DifferentAttribute SetsTo Predict
„Black“
only behavior-based
attributes
only circumstance-based
attributes
Almost no
prediction
possible! Prediction still
possible
(probably due to
„pct“ attribute)
Let‘sTry It Reducing the Features: Use Only
Behavior
previous model
with all features
DisparateTreatment Is Reduced (But So Is
Usefulness)
previous model
with all features
Let'sTry Using A DifferentTargetAttribute
Input attributes
was this person arrested /
summoned?
Training with A DifferentTarget: Arrests +
Summons
(only using circumstance-based attributes)
There should be
less bias in the
arrests, as it is
harder (but still
possible) to arrest
someone who is
innocent.
As Expected, Bias Is Reduced
No „preferential“
treatment evident for
white people in the data
(on the contrary)
Much better!
Better (But Still Imperfect)Treatment ByThe
Algorithm
Take-Aways
• Most training data that we use contains biases
• Some of these biases are implicit and not easy to recognize (if
we don‘t look)
• To protect people from discrimination, we need to record and
analyze their sensitive data (in a secure way)
• Machine learning and data analysis can uncover hidden biases
in processes (if we're transparent about the methods)
• Algorithmic systems can improve the fairness of manual
processes by ensuring no biases are present
Outlook:What Future ML Systems Could
Look Like
ML Algorithm
Non-protected
Input Data
Sanitized
Input Data
Protected
Input Data Explainer
explanations
results
Auditor
fairness metrics
Thanks!
Slides, code, literature and data will be made available here:
https://github.com/adewes/fatml-pydata
Contact me: ich@andreas-dewes.de (@japh44)
Image Credits:
https://gist.github.com/dannguyen/67ece10c6132282b1da2
https://commons.wikimedia.org/wiki/File:Deadpool_and_Predator_at_Big_Apple_Con_2009.jpg

Fairness and Transparency in Machine Learning

  • 1.
    Fairness and transparencyin machine learning Tools and techniques PyData Berlin – 2017 Andreas Dewes (@japh44)
  • 2.
  • 3.
    Fairness in MachineLearning • Fairness is not a technological problem, but unfair behavior can be replicated / automated using technology. • Machine learning systems are not per se fair or unfair, but have the potential to be either depending on how we use them. • We have a chance to eliminate unfairness by using machine learning and data analysis to make personal biases explicit and design systems that eliminate it!
  • 4.
    Discrimination Discrimination is treatmentor consideration of, or making a distinction in favor of or against, a person or thing based on the group, class, or category to which that person or thing is perceived to belong to rather than on individual merit. Protected attributes (examples): Ethnicity, Gender, Sexual Orientation, ...
  • 5.
    When is aprocess discriminating? Disparate Impact: Adverse impact of a process C on a given group X 𝑃 𝐶 = 𝑌𝐸𝑆 𝑋 = 0 𝑃 𝐶 = 𝑌𝐸𝑆 𝑋 = 1 < τ see e.g. "Certifying and Removing Disparate Impact" M. Feldman et. al.
  • 6.
    Estimating  withreal-world data τ = 𝑐/ 𝑎 + 𝑐 𝑑/ 𝑏 + 𝑑 c a d b
  • 7.
    Alternative Approaches: Individual-Based Fairness 𝑓𝑥1 − 𝑓 𝑥2 ≤ 𝐿 𝑥1 − 𝑥2 similar individual => similar treatment!
  • 8.
    Let‘s try to design afair & transparent algorithm
  • 9.
    NYC Stop & FriskDataset https://gist.github.com/dannguyen/67ece10c6132282b1da2 • Design a stop & frisk algorithm that is as fair as possible • Ensure it fulfills the other goals that we have for it
  • 10.
    InputVariables appearance-related behavior-related Attribute Name Description Age SUSPECT'SAGE Weight SUSPECT'S WEIGHT Ht_feet SUSPECT'S HEIGHT (FEET) Eyecolor SUSPECT'S EYE COLOR Haircolor SUSPECT'S HAIRCOLOR Race SUSPECT'S RACE Sex SUSPECT'S SEX Build SUSPECT'S BUILD CS_Cloth WEARING CLOTHES COMMONLY USED IN A CRIME CS_Objcs CARRYING SUSPICIOUS OBJECT CS_Bulge SUSPICIOUS BULGE CS_Descr FITS A RELEVANT DESCRIPTION RF_Attir INAPPROPRIATE ATTIRE FOR SEASON Attribute Name Description ac_evasv EVASIVE RESPONSE TO QUESTIONING ac_assoc ASSOCIATING WITH KNOWN CRIMINALS cs_lkout SUSPECT ACTING AS A LOOKOUT cs_drgtr ACTIONS INDICATIVE OF A DRUG TRANSACTION cs_casng CASING A VICTIM OR LOCATION cs_vcrim VIOLENT CRIME SUSPECTED ac_cgdir CHANGE DIRECTION AT SIGHT OF OFFICER cs_furtv FURTIVE MOVEMENTS ac_stsnd SIGHTS OR SOUNDS OF CRIMINAL ACTIVITY rf_othsw OTHER SUSPICION OF WEAPONS rf_knowl KNOWLEDGE OF SUSPECTS PRIOR CRIMINAL BEHAVIOR rf_vcact ACTIONS OF ENGAGING IN A VIOLENT CRIME rf_verbl VERBAL THREATS BY SUSPECT Attribute Name Description inout WAS STOP INSIDE OR OUTSIDE? trhsloc WAS LOCATION HOUSING OR TRANSIT AUTHORITY? timestop TIME OF STOP (HH:MM) pct PRECINCT OF STOP (FROM 1 TO 123) ac_prox m PROXIMITY TO SCENE OF OFFENSE cs_other OTHER ac_rept REPORT BY VICTIM / WITNESS / OFFICER ac_inves ONGOING INVESTIGATION ac_incid AREA HAS HIGH CRIME INCIDENCE ac_time TIME OF DAY FITS CRIME INCIDENCE circumstance-related ?
  • 11.
    Process Model Possible goals: Builda system that decides whether to frisk someone or Try to maximize discovery of criminals while not bothering law-abiding citizens. Do not discriminate against individual groups of people.
  • 12.
    Choosing A LossFunction Give a reward α if our algorithm correctly identifies a person to frisk Give a penalty -1 if our algorithm wrongly identifies a person to frisk α (weight parameter) „It‘s okay to frisk α +1 people to find one criminal“.
  • 13.
    Measuring Fairness viaDisparateTreatment
  • 14.
    Building a FirstModel Clean input data Select attributes Convert to binary values using „one hot“ method Train a classifier on the target value Measure the score and discrimination metrics Load CSV data into dataframe, discretize all attributes, clean input data. Use a logistic regression classifier to predict the target attribute. Split the data in training/test sets using a 70/30 split. Generate models for a range of α values and compare performance.
  • 15.
    First Attempt:To FriskOr NotTo Frisk… Input attributes was this person frisked?
  • 16.
    HowTo JudgeThe SuccessRate ofThe Algorithm Our algorithm should at least be as good as a random algorithm at picking people to frisk. It can „buy“ true positives by accepting false positives. The higher α is, the more profitable this trade becomes. Eventually we will have frisked all people, which is a solution to the problem (but not a good one…)
  • 17.
    Example: Predicting OnlyWithNoise (No Information) We give no useful information to the algorithm at all. It will therefore pick the action (frisk / not frisk) that will globally maximize the score when chosen for all people.
  • 18.
    Predicting „frisk“ withall available input attributes Now we give it all the input attributes that we got. It will make a prediction that is much better than randomly choosing a person to frisk.
  • 19.
    What does itmean for individual groups? There is strong mistreatment of individual groups. The algorithm learned to be just as biased as the training data.
  • 20.
    Where does thebias come from? Let‘s see! Predict „black“ from available attributes. The algorithm can easily differentiate between „white“ and „black“
  • 21.
    EliminatingThe Bias: DifferentApproaches Remove /Modify Data Points … 1 2 3 Constrain the Algorithm forbidden solutions allowed solutions …or change the target attribute! … 1 2 3 Remove Attributes
  • 22.
    Trying DifferentAttribute SetsToPredict „Black“ only behavior-based attributes only circumstance-based attributes Almost no prediction possible! Prediction still possible (probably due to „pct“ attribute)
  • 23.
    Let‘sTry It Reducingthe Features: Use Only Behavior previous model with all features
  • 24.
    DisparateTreatment Is Reduced(But So Is Usefulness) previous model with all features
  • 25.
    Let'sTry Using ADifferentTargetAttribute Input attributes was this person arrested / summoned?
  • 26.
    Training with ADifferentTarget: Arrests + Summons (only using circumstance-based attributes) There should be less bias in the arrests, as it is harder (but still possible) to arrest someone who is innocent.
  • 27.
    As Expected, BiasIs Reduced No „preferential“ treatment evident for white people in the data (on the contrary) Much better!
  • 28.
    Better (But StillImperfect)Treatment ByThe Algorithm
  • 29.
    Take-Aways • Most trainingdata that we use contains biases • Some of these biases are implicit and not easy to recognize (if we don‘t look) • To protect people from discrimination, we need to record and analyze their sensitive data (in a secure way) • Machine learning and data analysis can uncover hidden biases in processes (if we're transparent about the methods) • Algorithmic systems can improve the fairness of manual processes by ensuring no biases are present
  • 30.
    Outlook:What Future MLSystems Could Look Like ML Algorithm Non-protected Input Data Sanitized Input Data Protected Input Data Explainer explanations results Auditor fairness metrics
  • 31.
    Thanks! Slides, code, literatureand data will be made available here: https://github.com/adewes/fatml-pydata Contact me: ich@andreas-dewes.de (@japh44) Image Credits: https://gist.github.com/dannguyen/67ece10c6132282b1da2 https://commons.wikimedia.org/wiki/File:Deadpool_and_Predator_at_Big_Apple_Con_2009.jpg