Various attributes inferences attacks tested against fairness enforcing mechanisms
Project description
AIA_fairness
Code repository of the article. The repositries segments the pipeline as to isolate key componants of the experimental analysis.
Installation and dependencies
By using pypi :
pip install aia_fairness
Or clone the repository then run
pip install --editable .
in the directory containing pyproject.toml
All dependencies are specified in pyproject.toml and installed automatically by pip.
How to use
Global configuration parameters can be set by editing config.py
Dataset automatic download and processing
Part of the dataset uses the kaggle API to download the data.
Hence you need to include your API key in ~/.kaggle/kaggle.json.
aia_fairness provides automatic download, formatic and saving of the dataset used in the article.
To use this feature and thus saving data in the data_format directory simply run once
import aia_fairness.dataset_processing as dp
dp.fetch()
Then you can load any dataset easily form anywhere in your code with
import aia_fairness.dataset_processing as dp
data = dp.load_format(dset, attrib)
You can refer to the full implementation in test/target_training.py.
Running all the expriments form the paper
** Heavy computing power required **
One you have downloaded all the data you can run all the expirement of the article by running
python -m aia_fairness.experimental_stack
or import aia_fairness.experimental_stack in the python interpreter.
Training a target model
aia_fairness.models.target contains various target model type.
The target models available are :
RandomForestRandomForest_EGDfairlearn is used to impose EGDNeuralNetworkNeuralNetwork_FairgradOriginal implementation of the fairgrad paperNeuralNetwork_AdversarialDebiasingUses the fairlearn implementation of Adversarial Debisaing
For instance to train a random forest (based on sklearn) you can
import aia_fairness.models.target as targets
T = dp.split(data,0)
target.fit(T["train"]["x"], T["train"]["y"])
yhat = target.predict(T["test"]["x"])
Evaluation of a target model
aia_fairness.evaluation provides the metrics used in the article.
import aia_fairness.evaluation as evaluations
utility = evaluations.utility()
fairness = evaluations.fairness()
utility.add_result(T["test"]["y"], yhat, T["test"]["z"])
fairness.add_result(T["test"]["y"], yhat, T["test"]["z"])
utility.save(type(target).__name__,dset,attrib)
fairness.save(type(target).__name__,dset,attrib)
The save method, as called in the example, creates a directory structure of the form :
#|result/target/<target type>
#| |<name of the metric class>
#| | |<dset>
#| | | |<attrib>
#| | | | <Name of metric 1>.pickle
#| | | | <Name of metric 2>.pickle
#| | | | <Name of metric ..>.pickle
#| |<name of another metric class>
#| | |<dset>
#| | | |<attrib>
#| | | | <Name of another metric 1>.pickle
#| | | | <Name of another metric 2>.pickle
#| | | | <Name of another metric ..>.pickle
Training an attack
aia_fairness.models provides the two types of AIA attack described in the paper:
Classificationfor hard labelsRegressionfor soft labels
from aia_fairness.models import attack as attacks
aux = {"y":T["test"]["y"],
"z":T["test"]["z"],
"yhat":yhat}
aux_split = dp.split(aux,0)
classif = attacks.Classification()
classif.fit(aux_split["train"]["yhat"], aux_split["train"]["z"])
Evaluation of an attack
Similarly with evaluating the target model aia_fairness.evaluation.attack can be used to save the accuracy and the balanced accuracy of the attack.
Plots and graphs
TODO
Tests scripts
Various tests are provided in the test directory.
download_data.pyFetches all the data form the diferent sources (don't forget to set your kaggle API key)target_training.pyLoads a dataset, split it with 5-folding (cross validation), train a target model on the data, and computes the metrics for this target model
Directories structure
- data_processing contains code that downloads, preprocess and saves the dataset in a uniformed pickle format exploitable by the rest of the pipeline using
load_format(dataset,attribute)function of the utils.py file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aia_fairness-0.0.3.tar.gz.
File metadata
- Download URL: aia_fairness-0.0.3.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d16add869d03de6c1a051b4689d7452d6aa691b30b0c7a6ea4bbb2bf6e63436
|
|
| MD5 |
04243fe9f42e75d53dd952bd91e78f7d
|
|
| BLAKE2b-256 |
a629c6d3c9668501274ff3761134fd8c624ae7a7817d5bf16d0eec609252ac63
|
File details
Details for the file aia_fairness-0.0.3-py3-none-any.whl.
File metadata
- Download URL: aia_fairness-0.0.3-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caaa719b28690ff61b6386e8639f2e6e6223c61dd6f72e032d631c6c3927c7b3
|
|
| MD5 |
4438fd18820165b73379ee63f358b66f
|
|
| BLAKE2b-256 |
e3c04a9e2ec386998082ac9420bccda2e94dc5ec7e2d90713d6d2deca9d54053
|