Skip to main content

Documentation Status PyPI Downloads GitHub stars

Synthetic Data: Utility, Regulatory compliance, and Ethical privacy

The SURE package is an open-source Python library intended to be used for the assessment of the utility and privacy performance of any tabular synthetic dataset.

The SURE library features multiple Python modules that can be easily imported and seamlessly integrated into any Python script after installing the library.

Installation

To install the library run the following command in your terminal:

$ pip install clearbox-sure

Modules overview

The SURE library features the following modules:

  1. Preprocessor
  2. Statistical similarity metrics
  3. Model garden
  4. ML utility metrics
  5. Distance metrics
  6. Privacy attack sandbox
  7. Report generator

Preprocessor

The input datasets undergo manipulation by the preprocessor module, tailored to conform to the standard structure utilized across the subsequent processes. The Polars library used in the preprocessor makes this operation significantly faster compared to the use of other data processing libraries.

Utility

The statistical similarity metrics, the ML utility metrics and the model garden modules constitute the data utility evaluation part.

The statistical similarity module and the distance metrics module take as input the pre-processed datasets and carry out the operation to assess the statistical similarity between the datasets and how different the content of the synthetic dataset is from the one of the original dataset. In particular, The real and synthetic input datasets are used in the statistical similarity metrics module to assess how close the two datasets are in terms of statistical properties, such as mean, correlation, distribution.

The model garden executes a classification or regression task on the given dataset with multiple machine learning models, returning the performance metrics of each of the models tested on the given task and dataset.

The model garden module’s best performing models are employed in the machine learning utility metrics module to compute the usefulness of the synthetic data on a given ML task (classification or regression).

Privacy

The distance metrics and the privacy attack sandbox make up the synthetic data privacy assessment modules.

The distance metrics module computes the Gower distance between the two input datasets and the distance to the closest record for each line of the first dataset.

The ML privacy attack sandbox allows to simulate a Membership Inference Attack for re-identification of vulnerable records identified with the distance metrics module and evaluate how exposed the synthetic dataset is to this kind of assault.

Report

Eventually, the report generator provides a summary of the utility and privacy metrics computed in the previous modules, providing a visual digest with charts and tables of the results.

This following diagram serves as a visual representation of how each module contributes to the utility-privacy assessment process and highlights the seamless interconnection and synergy between individual blocks.

drawing

Usage

The library leverages Polars, which ensures faster computations compared to other data manipulation libraries. It supports both Polars and Pandas dataframes.

The user must provide both the original real training dataset (which was used to train the generative model that produced the synthetic dataset), the real holdout dataset (which was NOT used to train the generative model that produced the synthetic dataset) and the corresponding synthetic dataset to enable the library's modules to perform the necessary computations for evaluation.

Below is a code snippet example for the usage of the library:

# Import the necessary modules from the SURE library
from sure import Preprocessor, report
from sure.utility import (compute_statistical_metrics, compute_mutual_info,
			  compute_utility_metrics_class,
			  detection,
			  query_power)
from sure.privacy import (distance_to_closest_record, dcr_stats, number_of_dcr_equal_to_zero, validation_dcr_test, 
			  adversary_dataset, membership_inference_test)

# Assuming real_data, valid_data and synth_data are three pandas DataFrames

# Preprocessor initialization and query execution on the real, synthetic and validation datasets
preprocessor            = Preprocessor(real_data, num_fill_null='forward', scaling='standardize')

real_data_preprocessed  = preprocessor.transform(real_data)
valid_data_preprocessed = preprocessor.transform(valid_data)
synth_data_preprocessed = preprocessor.transform(synth_data)

# Statistical properties and mutual information
num_features_stats, cat_features_stats, temporal_feat_stats = compute_statistical_metrics(real_data, synth_data)
corr_real, corr_synth, corr_difference                      = compute_mutual_info(real_data_preprocessed, synth_data_preprocessed)

# ML utility: TSTR - Train on Synthetic, Test on Real
X_train      = real_data_preprocessed.drop("label", axis=1) # Assuming the datasets have a “label” column for the machine learning task they are intended for
y_train      = real_data_preprocessed["label"]
X_synth      = synth_data_preprocessed.drop("label", axis=1)
y_synth      = synth_data_preprocessed["label"]
X_test       = valid_data_preprocessed.drop("label", axis=1).limit(10000) # Test the trained models on a portion of the original real dataset (first 10k rows)
y_test       = valid_data_preprocessed["label"].limit(10000)
TSTR_metrics = compute_utility_metrics_class(X_train, X_synth, X_test, y_train, y_synth, y_test)

# Distance to closest record
dcr_synth_train       = distance_to_closest_record("synth_train", synth_data, real_data)
dcr_synth_valid       = distance_to_closest_record("synth_val", synth_data, valid_data)
dcr_stats_synth_train = dcr_stats("synth_train", dcr_synth_train)
dcr_stats_synth_valid = dcr_stats("synth_val", dcr_synth_valid)
dcr_zero_synth_train  = number_of_dcr_equal_to_zero("synth_train", dcr_synth_train)
dcr_zero_synth_valid  = number_of_dcr_equal_to_zero("synth_val", dcr_synth_valid)
share                 = validation_dcr_test(dcr_synth_train, dcr_synth_valid)

# Detection Score
detection_score = detection(real_data, synth_data, preprocessor)

# Query Power
query_power_score = query_power(real_data, synth_data, preprocessor)

# ML privacy attack sandbox initialization and simulation
adversary_df = adversary_dataset(real_data, valid_data)
# The function adversary_dataset adds a column "privacy_test_is_training" to the adversary dataset, indicating whether the record was part of the training set or not
adversary_guesses_ground_truth = adversary_df["privacy_test_is_training"] 
MIA = membership_inference_test(adversary_df, synth_data, adversary_guesses_ground_truth)

# Report generation as HTML page
report(real_data, synth_data)

Follow the step-by-step guide to test the library.

Metadata

Release files for clearbox-sure 0.2.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for clearbox-sure 0.2.16
File
clearbox_sure-0.2.16-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
clearbox_sure-0.2.16-cp312-cp312-macosx_10_13_universal2.whl CPython 3.12 CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) Details
clearbox_sure-0.2.16-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
clearbox_sure-0.2.16-cp311-cp311-macosx_10_9_universal2.whl CPython 3.11 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) Details
clearbox_sure-0.2.16-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
clearbox_sure-0.2.16-cp310-cp310-macosx_10_9_universal2.whl CPython 3.10 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) Details

Total release size: 4.4 MB

Release files / clearbox_sure-0.2.16-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL clearbox_sure-0.2.16-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c404c3bf554d0d2916d423bb2f2de7647e3802a6a90e8e673da62f79649314ed
BLAKE2b-256 checksum
How to use checksums
c3b796c63f782565d1d5af801875e72b8531e8873dc038b1f8b96e7f855e2b97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / clearbox_sure-0.2.16-cp312-cp312-macosx_10_13_universal2.whl

Download URL clearbox_sure-0.2.16-cp312-cp312-macosx_10_13_universal2.whl
Size 374.5 kB
Tags CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
564abe9a3f632ce5ac454eee14c15eac991ccaad09128b997c360fa9446846b3
BLAKE2b-256 checksum
How to use checksums
c955bed66082dfd6d0a691eebd2e6064e63da4f7fd14190cdc600d498450fb25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / clearbox_sure-0.2.16-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL clearbox_sure-0.2.16-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
dbba173527cc8a08b92e66da75deb12fa38ef022e9ed3f313475c227907cb51e
BLAKE2b-256 checksum
How to use checksums
6b2e986d5564ca6d30488702779f357b22a46114e4e6f0695af97bb939901d63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / clearbox_sure-0.2.16-cp311-cp311-macosx_10_9_universal2.whl

Download URL clearbox_sure-0.2.16-cp311-cp311-macosx_10_9_universal2.whl
Size 380.6 kB
Tags CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
cd815f719238b9adc44b74b74b6077c0657466db8c9d738ad1be715b8bac8710
BLAKE2b-256 checksum
How to use checksums
6a05ca353724ab6db5b47cb4f10627927da9a12562a77e85872743ede5ef7f68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / clearbox_sure-0.2.16-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL clearbox_sure-0.2.16-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a7c763a4e8d4925b9819ad12d1a261716561b87b8c21b4bb459fe73177eb2c9e
BLAKE2b-256 checksum
How to use checksums
fde918c7514ae401d134f29321631361ceb5ffc14ffa65ae22e1ae7033572a79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / clearbox_sure-0.2.16-cp310-cp310-macosx_10_9_universal2.whl

Download URL clearbox_sure-0.2.16-cp310-cp310-macosx_10_9_universal2.whl
Size 377.7 kB
Tags CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
02c54d677a32487e710783b805360cf6ad84ed74fa45b033eacfe895bbcbcdf0
BLAKE2b-256 checksum
How to use checksums
142d10efc04b743bc2360f1bb56cde1c1c59aeafd5cca297b31f9fe2e13d76a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.2.16 This release

6 release files

0.2.15

6 release files

0.2.14

3 release files

0.2.13

3 release files

0.2.12

3 release files

0.2.11

3 release files

0.2.10

3 release files

0.2.9

3 release files

0.2.8

3 release files

0.2.7

3 release files

0.2.6

6 release files

0.2.5

6 release files

0.2.4

6 release files

0.2.3

6 release files

0.2.2

6 release files

0.2.1

6 release files

0.2.0

6 release files

0.1.7

4 release files

0.1.6

3 release files

0.1.5

4 release files

0.1.3

4 release files

0.1.2

4 release files

0.1.1

4 release files

0.1

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page