SynthCity: A Library for Generating and Evaluating Synthetic Data
SynthCity is an open-source Python library developed by the van der Schaar Lab at the University of Cambridge. It specializes in generating and evaluating synthetic tabular, time-series, and survival data. The library supports a wide range of generative models, each tailored to specific data types and privacy requirements, making it a valuable tool for researchers focused on privacy-preserving data sharing. Released under the Apache 2.0 license, SynthCity is designed to be extensible, modular, and compatible with various machine learning frameworks.
Its architecture is plugin-based, allowing users to easily extend functionality by integrating new generative models or evaluation metrics.
SynthCity does not handle missing data by default, requiring users to preprocess datasets using tools like HyperImpute before generating synthetic data.
How It Works
Users can list available plugins by category, such as general-purpose, privacy-focused, or domain-specific models, and load them dynamically.
The library supports three primary data types: tabular, time-series, and survival data. Survival analysis data is handled by SurvivalAnalysisDataLoader, ensuring compatibility with models like SurvivalGAN or SurVAE.
Once a model is trained, users can generate synthetic data by specifying the desired sample count.
Evaluation metrics are central to SynthCity’s functionality. The library includes metrics for assessing fidelity, privacy, and fairness in synthetic datasets. These metrics quantify attributes such as data type consistency, leakage risk, and distributional similarity between real and synthetic data.
Use Cases
SynthCity is primarily used in research focused on privacy-preserving data sharing, where synthetic data serves as a secure alternative to raw datasets. Its generative models are designed to minimize identifiability risks while preserving the statistical properties of the original data. For example, the AdsGAN model explicitly reduces patient re-identification probabilities, making it suitable for healthcare applications where data privacy is critical.
The library supports time-series data generation through models like TimeGAN and FourierFlows, which are optimized for capturing temporal dependencies. Similarly, SurvivalGAN and SurVAE enable the generation of synthetic survival data, which is valuable in clinical trials and actuarial research.
SynthCity also addresses fairness in synthetic data through models like DECAF, which embeds causal relationships into the generative process.
Beyond privacy and fairness, SynthCity supports domain adaptation tasks using RadialGAN. This model enables the translation of data between related but distinct domains, augmenting datasets for predictive modeling in scenarios where data scarcity is a challenge.
Generative Models
SynthCity integrates a diverse set of generative models categorized by their primary use case. General-purpose models include GAN-based approaches like AdsGAN, CTGAN, and PATEGAN, as well as VAE-based models such as TVAE and RTVAE. These models are designed to handle tabular data with mixed categorical and continuous features, ensuring versatility across domains.
For time-series data, SynthCity offers TimeGAN, FourierFlows, and TimeVAE. TimeGAN combines supervised and adversarial learning to generate realistic time-series data, while FourierFlows uses spectral representations to model frequency-domain characteristics.
Survival analysis is supported through SurvivalGAN, SurvivalCTGAN, and SurVAE. For example, SurvivalGAN approximates survival functions directly, ensuring that synthetic data reflects the original dataset’s censoring patterns.
Privacy-focused models in SynthCity include DECAF, DP-GAN, AdsGAN, and PrivBayes. DECAF embeds causal structures to generate fair synthetic data, while DP-GAN and AdsGAN incorporate differential privacy mechanisms to limit identifiability risks.
Evaluation Metrics
The library provides a comprehensive suite of evaluation metrics to assess the quality of synthetic data. These metrics are grouped into categories measuring fidelity, privacy, and fairness. Fidelity metrics include data type consistency, leakage risk, and distributional similarity, while privacy metrics quantify the risk of re-identification or attribute disclosure. Fairness metrics evaluate the presence of biases in synthetic datasets, ensuring compliance with ethical guidelines.
Key metrics include the Jensen-Shannon divergence, Wasserstein distance, and empirical maximum mean discrepancy, which compare the distributions of real and synthetic data. Additional metrics like alpha-precision and beta-recall evaluate the trade-off between coverage and authenticity in synthetic datasets. These metrics are automated through the Benchmarks module, allowing users to systematically compare multiple generative models.
Plugin Architecture and Extensibility
SynthCity’s plugin architecture enables users to extend its functionality by integrating custom generative models or evaluation metrics.
Serialization and Reproducibility
SynthCity includes serialization methods to save and load trained models, ensuring reproducibility in research workflows.
Additionally, SynthCity provides tools for handling missing data, though users must preprocess datasets using external libraries like HyperImpute before training generative models.
Technical Implementation and Dependencies
SynthCity is implemented in Python and relies on several key dependencies, including PyTorch, scikit-learn, and pandas. Dependencies are managed through a flexible installation system, allowing users to install the core library or additional extensions as needed.
The library’s architecture is modular, with each generative model implemented as a separate plugin.
The library’s documentation and tutorials provide step-by-step guidance for users, from basic data generation to advanced benchmarking and model extension.
