Skip to main content

A differentially private data synthesizer and fairness intervention benchmark framework

Project description

DP+Fair Benchmarking Framework

This repository provides a Python framework for benchmarking fairness mechanisms on Differentially Private Synthetic Data.


Features

  • ⚡ Simple, reproducible setup for benchmarking algorithms
  • 🧩 Flexible API to plug in any classifier implementing fit, predict, and predict_proba
  • 📊 Pre-offered datasets included under data/
  • 🔬 Configurable experiment settings: dataset schema, dataset synthesizer, seeds, privacy-budget, input/outputs, classifier, data pre-processing.

Installation

From source To install, either use PyPi to isntall it, or clone the repository and install dependencies:

git clone https://github.com/vinicius-verona/dp-fair-intervention-benchmark.git
cd dp-fair-intervention-benchmark

python3 -m venv dpfair-env
source dpfair-env/bin/activate 

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -e .

Using PyPi (SUGGESTED)

python3 -m venv dpfair-env
source dpfair-env/bin/activate 
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install BenchmarkDPFair

Repository Structure

├── data/         # Pre-offered datasets
├── src/          # Core source code
├── examples/     # Some demo
├── tests/        # Unit tests
└── README.md

Quick Start

Here is a dummy example:

import argparse
from typing import List, Union
from BenchmarkDPFair.DataGenerator import generate_data, DatasetGeneratorConfig
from BenchmarkDPFair.Benchmark import benchmark, BenchmarkInfo, BenchmarkDatasetConfig

from sklearn.linear_model import LogisticRegression

ESTIMATOR_PARAMS = {
    'max_iter': 10000,
    'solver': 'saga',
    'l1_ratio': 0.5,
    'C': 0.8
}

lr = LogisticRegression
classifiers = [lr]
ckwargs = [
    ESTIMATOR_PARAMS,
]
classifier_name = ["LR"]
combinations = [
    (0, 0),
    (0, 1),
]

synths = ["aim", "mst"]

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Arguments of Data Generation for Adult")

    parser.add_argument(
        "--seeds", "-s",
        nargs="+",        # 1 or more values
        type=int          # convert automatically to int
    )

    args = parser.parse_args()
    seeds = args.seeds
    
    eps : List[Union[int,float]] = [.05, .1]

    for synthesizer in synths:
        for s in seeds:
            data_conf = DatasetGeneratorConfig(
                name = "Compas",
                target= "two_year_recid",
                synthesizer = synthesizer,
                root_dir="./data",
                sensitive_attr = "race",
                categorical_cols = ['race', 'score_text', 'c_charge_degree','age', 'sex', 'two_year_recid'],
                sensitive_cols = ['race', 'sex'],
                ordinal_cols = ['priors_count'],
                privacy_budgets=eps,
                binary_encoder=binary_encode,
                seed = s,
                test_split_size=0.4,
                data_filter = filter_compas
            )

            generate_data(f"compas.csv", "", data_conf, "./data", verbose=True)

    for clf_idx, syn_idx in combinations:
        classifier = classifiers[clf_idx]
        synth = synths[syn_idx]

        benchmark_config = BenchmarkInfo(
            dp_method=synth,
            output_dir=f"./output/Dummy-Compas/{classifier_name[clf_idx]}/",
            seeds=seeds,
            eps = eps,
            classifier=classifier,
            classifier_kwargs=ckwargs[clf_idx]
        )

        benchmark_dataset = BenchmarkDatasetConfig(
            name = "Compas",
            target= "two_year_recid",
            root_dir="./data",
            sensitive_attr = "race",
            index_col="Unnamed: 0",
            categorical_cols = ['race', 'score_text', 'c_charge_degree','age', 'sex', 'two_year_recid'],
            ordinal_cols=["priors_count"],
            sensitive_cols = ['race', 'sex'],
        )


        benchmark(benchmark_info=benchmark_config, data_conf=benchmark_dataset)

More detailed examples can be found in the example/ directory.


License

License: MIT


Contributing

Contributions are welcome:

  • Open an issue for bug reports or feature requests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

benchmarkdpfair-0.2.4.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

benchmarkdpfair-0.2.4-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file benchmarkdpfair-0.2.4.tar.gz.

File metadata

  • Download URL: benchmarkdpfair-0.2.4.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for benchmarkdpfair-0.2.4.tar.gz
Algorithm Hash digest
SHA256 f2e5127e6c5ce424cfb3d1a20a8616a003088f01d9714e0fa824ccec8ce4ebe8
MD5 96323a5a3594d247e26ae1aadf4a8f9c
BLAKE2b-256 7829c0a020fcda263b8c0a4f24af9eb4c7ebb2ada9b56e0359e3af4676dfa4a0

See more details on using hashes here.

File details

Details for the file benchmarkdpfair-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for benchmarkdpfair-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9f3531b0a9e21449475ba5fcacd2fc28ed63ea7c347c8c82facdf124e295e0e7
MD5 fa17f49f98f30adae1771a7c2463243a
BLAKE2b-256 e9e9811e04951c0bccd6de35608d80c2478053c58776efe08c9ad3749042bdd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page