Skip to main content

Local differential privacy mechanisms

Project description

License: Apache 2.0 codecov PyPI Documentation Status Publish Package in PyPI CI/CD Pipeline Code Coverage Python version

TrasgoDP implements different mechanims for ε-differential privacy and (ε, δ)-differential privacy. The mechanisms are implemented for being used under a local approach, adding noise directly to the raw data. Two types of mechanims are implemented:

  • For numerical records: Laplace and Gaussian mechanisms. The implementation includes a final clipping applyied on the data with DP.
  • For categorical records: Exponential mechanism and Randomized Response (both for binary attributes and the k-ary version).

This library provides dedicated function designed for being applied on both pandas dataframes and lists/numpy arrays.

Getting started

For applying DP mechanisms to a column of a dataframe you need to introduce:

  • The pandas dataframe with the data.
  • The column in the dataframe to be privatized.
  • The privacy budget (ε).
  • The probability of exceeding the privacy budget (δ) in case of numerical attributes and the Gaussian mechanism.
  • The uper and lower bounds for numerical attributes (optional).

Example: apply DP to the adult dataset with the Laplace mechanism for the column age and the Exponential mechanism for the column workclass:

import pandas as pd
from trasgodp.numerical import dp_clip_laplace
from trasgodp.categorical import dp_exponential

# Read and process the data
data = pd.read_csv("examples/adult.csv")
data.columns = data.columns.str.strip()
cols = [
    "workclass",
    "education",
    "marital-status",
    "occupation",
    "sex",
    "native-country",
]
for col in cols:
    data[col] = data[col].str.strip()

# Apply DP for the attribute age:
column_num = "age"
epsilon1 = 10
df = dp_clip_laplace(data, column_num, epsilon1, new_column=True)

# Apply DP for the attribute workclass:
column_cat = "workclass"
epsilon2 = 5
df = dp_exponential(data, column_cat, epsilon2, new_column=True)

Warning

This project is under active development.

License

This project is licensed under the Apache 2.0 license.

Funding and acknowledgments

This work is funded by European Union through the SIESTA project (Horizon Europe) under Grant number 101131957.

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

trasgodp-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

trasgodp-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file trasgodp-0.1.0.tar.gz.

File metadata

  • Download URL: trasgodp-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for trasgodp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f585c54afd94c5c396e40d18654d4e6b37e068d169d2c139c6566c5a04871e8
MD5 e171c6b604c6f2f6316a4c3c44994bc1
BLAKE2b-256 a0d92f163b7cf6bec4a7b2b39bc1ef5cbcd62fdb8aa4e2476c2a3e7f16448bcd

See more details on using hashes here.

File details

Details for the file trasgodp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: trasgodp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for trasgodp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6529d2e57675b4fd75b9ccfa8c42ec843a26368790274757a94f026d66fae7c9
MD5 08b2b0a758aab6a796c4823007c0eca9
BLAKE2b-256 2786535f95fa7bff4e862c65d3a11a54c022fed26b77aeed8e5f3ca3f6b29790

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