aif360.algorithms.inprocessing
.GerryFairClassifier
- class aif360.algorithms.inprocessing.GerryFairClassifier(C=10, printflag=False, heatmapflag=False, heatmap_iter=10, heatmap_path='.', max_iters=10, gamma=0.01, fairness_def='FP', predictor=LinearRegression())[source]
Model is an algorithm for learning classifiers that are fair with respect to rich subgroups.
Rich subgroups are defined by (linear) functions over the sensitive attributes, and fairness notions are statistical: false positive, false negative, and statistical parity rates. This implementation uses a max of two regressions as a cost-sensitive classification oracle, and supports linear regression, support vector machines, decision trees, and kernel regression. For details see:
References
Initialize Model Object and set hyperparameters.
- Parameters:
C – Maximum L1 Norm for the Dual Variables (hyperparameter)
printflag – Print Output Flag
heatmapflag – Save Heatmaps every heatmap_iter Flag
heatmap_iter – Save Heatmaps every heatmap_iter
heatmap_path – Save Heatmaps path
max_iters – Time Horizon for the fictitious play dynamic.
gamma – Fairness Approximation Paramater
fairness_def – Fairness notion, FP, FN, SP.
errors – see fit()
fairness_violations – see fit()
predictor – Hypothesis class for the Learner. Supports LR, SVM, KR, Trees.
Methods
Run Fictitious play to compute the approximately fair classifier.
fit_predict
Train a model on the input and predict the labels.
fit_transform
Train a model on the input and transform the dataset accordingly.
Helper Function to generate the heatmap at the current time.
Assumes Model has FP specified for metric.
Return dataset object where labels are the predictions returned by the fitted model.
Helper function to print outputs at each iteration of fit.
Helper Function to save the heatmap.
transform
Return a new dataset generated by running this Transformer on the input.
- __init__(C=10, printflag=False, heatmapflag=False, heatmap_iter=10, heatmap_path='.', max_iters=10, gamma=0.01, fairness_def='FP', predictor=LinearRegression())[source]
Initialize Model Object and set hyperparameters.
- Parameters:
C – Maximum L1 Norm for the Dual Variables (hyperparameter)
printflag – Print Output Flag
heatmapflag – Save Heatmaps every heatmap_iter Flag
heatmap_iter – Save Heatmaps every heatmap_iter
heatmap_path – Save Heatmaps path
max_iters – Time Horizon for the fictitious play dynamic.
gamma – Fairness Approximation Paramater
fairness_def – Fairness notion, FP, FN, SP.
errors – see fit()
fairness_violations – see fit()
predictor – Hypothesis class for the Learner. Supports LR, SVM, KR, Trees.
- fit(dataset, early_termination=True)[source]
Run Fictitious play to compute the approximately fair classifier.
- Parameters:
dataset – dataset object with its own class definition in datasets folder inherits from class StandardDataset.
early_termination – Terminate Early if Auditor can’t find fairness violation of more than gamma.
- Returns:
Self
- generate_heatmap(dataset, predictions, vmin=None, vmax=None, cols_index=[0, 1], eta=0.1)[source]
Helper Function to generate the heatmap at the current time.
- Parameters:
iteration – current iteration
dataset – dataset object with its own class definition in datasets folder inherits from class StandardDataset.
predictions – predictions of the model self on dataset.
vmin – see documentation of heatmap.py heat_map function
vmax – see documentation of heatmap.py heat_map function
- pareto(dataset, gamma_list)[source]
Assumes Model has FP specified for metric. Trains for each value of gamma, returns error, FP (via training), and FN (via auditing) values.
- Parameters:
dataset – dataset object with its own class definition in datasets folder inherits from class StandardDataset.
gamma_list – the list of gamma values to generate the pareto curve
- Returns:
list of errors, list of fp violations of those models, list of fn violations of those models
- predict(dataset, threshold=0.5)[source]
Return dataset object where labels are the predictions returned by the fitted model.
- Parameters:
dataset – dataset object with its own class definition in datasets folder inherits from class StandardDataset.
threshold – The positive prediction cutoff for the soft-classifier.
- Returns:
dataset_new – modified dataset object where the labels attribute are the predictions returned by the self model
- print_outputs(iteration, error, group)[source]
Helper function to print outputs at each iteration of fit.
- Parameters:
iteration – current iter
error – most recent error
group – most recent group found by the auditor
- save_heatmap(iteration, dataset, predictions, vmin, vmax)[source]
Helper Function to save the heatmap.
- Parameters:
iteration – current iteration
dataset – dataset object with its own class definition in datasets folder inherits from class StandardDataset.
predictions – predictions of the model self on dataset.
vmin – see documentation of heatmap.py heat_map function
vmax – see documentation of heatmap.py heat_map function
- Returns:
(vmin, vmax)