Skip to main content

Python implementation of the SynDiffix synthetic data generation mechanism.

Project description

Overview

SynDiffix is an open-source tool for generating statistically-accurate and strongly anonymous synthetic data from structured data. Compared to existing open-source and proprietary commercial approaches, SynDiffix is

  • many times more accurate,
  • has comparable or better ML efficacy,
  • runs as fast or faster,
  • has stronger anonymization.

Purpose

Synthetic data has two primary use cases:

  1. Descriptive analytics (histograms, heatmaps, column correlations, basic statistics like counting, averages, standard deviations, and so on)
  2. Machine learning (building models)

While SynDiffix serves both use cases, it is especially good at descriptive analytics. The quality of descriptive analytics is many times that of other synthetic data products.

Obtaining this improvement, however, requires a different usage style compared to other products. The intended usage style of other products is "one size fits all": a single synthetic dataset serves all use cases. By contrast, with SynDiffix, a different tailored synthetic dataset should be produced for each use case.

Install

Install with pip:

pip install syndiffix

Requires python 3.10 or later.

Usage

Usage can be as simple as:

from syndiffix import Synthesizer

df_synthetic = Synthesizer(df_original).sample()

This will create a new Pandas dataframe containing synthetic data, with the same number of columns and the similar number of rows as in the input dataframe.

The script example_simple.py gives a simple CSV-in-CSV-out example for generating synthetic data.

Maximizing data accuracy

Data accuracy is maximized by synthesizing only the columns required for the analytic task. For instance, if the goal is to understand the correlation between two columns col1 and col2, then only those columns should be synthesized:

from syndiffix import Synthesizer

df_synthetic = Synthesizer(df_original[['col1','col2']]).sample()

Note that anonymity is preserved regardless of how many different synthetic dataframes are generated from any given column.

Maximizing ML efficacy relative to a given target column

When the use case is producing an ML model for a given target column 'your_target_col', the target column is specified as:

from syndiffix import Synthesizer

df_synthetic = Synthesizer(df_original, target_column='your_target_col')

Note that the quality of the predictive model for the target column will be much better than when not specifying the target column. If a model is needed for a different target column, then a separate synthetic dataframe should be created.

Managing protected entities

A protected entity is the thing in the dataframe whose anonymity is being protected. Normally this is a person, but could be a device used by a person or really anything else.

If there are multiple rows per protected entity (e.g. event or time-series data), then there must be a column that identifies the protected entity, and this column must be conveyed in its own dataframe. Failing to do so compromises anonymity.

If the column identifying the protected entity is 'pid_col', then it is specified as:

from syndiffix import Synthesizer

df_pid = df_original[["pid_col"]]
df_original = df_original.drop(columns=["pid_col"])
df_synthetic = Synthesizer(df_original, pids=df_pid).sample()

Note that dropping 'pid_col' from df_original is not strictly necessary, but doing so leads to slightly higher quality data and faster execution time.

A dataframe can have multiple protected entities. Examples include sender and receiver in a banking transaction, or patient and doctor in a medical database. If the columns identifying two protected entities are 'pid_col1' and 'pid_col2', then they are specified as:

from syndiffix import Synthesizer

pid_columns = ["pid_col1", "pid_col2"]
df_pids = df_original[pid_columns]
df_original = df_original.drop(columns=pid_columns)
df_synthetic = Synthesizer(df_original, pids=df_pids).sample()

Other parameters

There are a wide variety of parameters that control the operation of SynDiffix. They are documented here.

Development

Prerequisites: poetry

  • Installation: poetry install

Activate poetry environment: poetry shell. (can skip, then prepend poetry run to the following commands)

  • Format: black . && isort .
  • Test: pytest .
  • Check: flake8 . && mypy . && black --check . && isort . --check

Implementation details

A step-by-step description of the algorithm can be found here.

A paper describing the design of SynDiffix, its performance, and its anonymity properties can be found here on ArXiv.

A per-dimension range is internally called an interval (and handled by the Interval class), in order to avoid potential name clashes with the native Python range API.

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

syndiffix-1.0.0b0.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

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

syndiffix-1.0.0b0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file syndiffix-1.0.0b0.tar.gz.

File metadata

  • Download URL: syndiffix-1.0.0b0.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for syndiffix-1.0.0b0.tar.gz
Algorithm Hash digest
SHA256 4ed362e02b839ee4146ef0d93e18a518ca6ad39a0ad41ac232fe3c283817a2db
MD5 2407f793adf8845ffe5f1f4d8f9d40f7
BLAKE2b-256 4f12eb8e8c6f643e862f61497b3b69c312d53a2725b73aa6aa368572500f8f1e

See more details on using hashes here.

File details

Details for the file syndiffix-1.0.0b0-py3-none-any.whl.

File metadata

  • Download URL: syndiffix-1.0.0b0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for syndiffix-1.0.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f5aaffa4e5b708cb23bf7e6b32e1b9c554129d808a95ac0605d53a4ff0c83be
MD5 647f39d6f29f9bddf4030174927069a6
BLAKE2b-256 8205ed0968b4a480d67608ee6db312363ce49a7a703fb50feab8d9ec723fe9d5

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